public class PaletteSetItem : PaletteSet
{
static PaletteSetItem instance = null;
static Guid guid = new Guid("{f9fead11-f73b-48b3-84c2-bd93b02df9bc}");
const string showCommand = "MyPalette";
private SolidColorBrush backgroundColor; //this is used to store the palette background color if needed
public static MyPalette MyPaletteCtrl { get; set; }
public PaletteSetItem()
: base(showCommand, showCommand, guid)
{
try
{
//Add the icon to the palette
base.Icon = MyIcon;
//Set the Palette size.
base.Size = new Size(400, 800);
//Changing background color based on System variable
//Following ideas here: https://www.theswamp.org/index.php?topic=47877.0
//Using Jetbrains DotPeek on AdUiPalettes was able to identify and pull the PaletteThemeDefaults
//Then converting color to a brush
MyPaletteCtrl = new MyPalette();
//Check theme to set the initial color and the reactors
CheckTheme();
//Set Palette background color
MyPaletteCtrl.Background = backgroundColor;
//Add the palette
base.AddVisual("MyPalette", MyPaletteCtrl, true);
Application.SystemVariableChanged += new Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(variableChanged);
}
catch (Exception ex)
{
//Error loading palette
}
}
protected override void OnPaletteSetClosed()
{
Application.SystemVariableChanged -= new Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(variableChanged);
}
public static void PaletteSetItemCommand()
{
instance = new PaletteSetItem();
instance.Visible = true;
}
private void variableChanged(object o, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
{
if (e.Name == @"COLORTHEME" && e.Changed)
CheckTheme();
//Set Palette background color
MyPaletteCtrl.Background = backgroundColor;
}
private void CheckTheme()
{
if (Application.Version.Major > 19)
{
//Background color is set based on the theme color
if (System.Convert.ToInt32(Application.GetSystemVariable(@"COLORTHEME")) == 1)
{
Autodesk.Windows.Palettes.PaletteTheme pt = new Autodesk.Windows.Palettes.PaletteTheme(Autodesk.Windows.Palettes.PaletteThemeDefaults.LightOverallColor);
backgroundColor = new SolidColorBrush(pt.PaletteTabBackgroundColor);
}
else
{
Autodesk.Windows.Palettes.PaletteTheme pt = new Autodesk.Windows.Palettes.PaletteTheme(Autodesk.Windows.Palettes.PaletteThemeDefaults.DarkOverallColor);
backgroundColor = new SolidColorBrush(pt.PaletteTabBackgroundColor);
}
}
else
{
//Sets a default gray color just so there's something
backgroundColor = (SolidColorBrush)new BrushConverter().ConvertFrom(@"#808080");
}
}
}
(setq acadobject (vlax-get-acad-object))
(setq acadpref (vlax-get-property acadobject 'preferences))
(setq acaddisp (vlax-get-property acadpref 'display))
(vlax-put-property acaddisp 'GraphicsWinmodelBackgrndColor 65986) ;;Model space background
(vlax-put-property acaddisp 'GraphicsWinLayoutBackgrndColor 63434) ;;command area
(vlax-put-property acaddisp 'ModelCrosshairColor 865785);; crosshairs
(vlax-put-property acaddisp 'TextWinBackgrndColor 3687) ;;command area