public class Command
{
static PaletteSet palette;
static bool wasVisible;
/// <summary>
/// Creates the palette if it did not already exist, and shwos it.
/// </summary>
[CommandMethod("test" )]
public static void CreateGridPanel()
{
if (palette == null)
{
palette = new PaletteSet("CaiGrid", "CONVPALETTE", new Guid("{929CAC46-8606-4580-A953-238B70CA76A1}"));
palette.Style =
PaletteSetStyles.ShowAutoHideButton |
PaletteSetStyles.ShowCloseButton |
PaletteSetStyles.ShowPropertiesMenu;
palette.MinimumSize = new System.Drawing.Size(410, 240);
palette.AddVisual("CaiGrid", new GridView());
// Automatically hides the palette while there is no active document.
var docs = Application.DocumentManager;
docs.DocumentBecameCurrent += (s, e) => palette.Visible = e.Document == null ? false : wasVisible;
docs.DocumentCreated += (s, e) => palette.Visible = wasVisible;
docs.DocumentToBeDeactivated += (s, e) => wasVisible = palette.Visible;
docs.DocumentToBeDestroyed += (s, e) =>
{
wasVisible = palette.Visible;
if (docs.Count == 1)
palette.Visible = false;
};
}
palette.Visible = true;
}
}
Once again there’s our important rule of thumb when it comes to implementing a modeless UI: rather than manually locking the current document, it’s safer to define a command – which will implicitly lock the current document – and call that from the UI via SendStringToExecute().
Hi,
From Kean Walmsley's blog (http://through-the-interface.typepad.com/through_the_interface/2011/02/managing-drag-drop-from-a-palette-into-autocad-using-net.html):QuoteOnce again there’s our important rule of thumb when it comes to implementing a modeless UI: rather than manually locking the current document, it’s safer to define a command – which will implicitly lock the current document – and call that from the UI via SendStringToExecute().
How does one "manually" lock a document anyway XD ?