To access the system setting Preference in AutoCAD, you must call the com api to add a reference to Autodesk. AutoCAD. Interop:
Directly run the Code:
Using Autodesk. AutoCAD. Runtime;
Using Autodesk. AutoCAD. ApplicationServices;
Using Autodesk. AutoCAD. DatabaseServices;
Using Autodesk. AutoCAD. EditorInput;
Using Autodesk. AutoCAD. Interop;
Using System. Drawing;
[CommandMethod ("GetBkClr")]
Public void GetBkGndColor ()
{
// Access the Preferences object
AcadPreferences acPrefComObj = (AcadPreferences) Application. Preferences;
Uint clr = acPrefComObj. Display. GraphicsWinLayoutBackgrndColor;
Ed. WriteMessage (UIntToColor (clr). ToString ());
}
[CommandMethod ("SetBKClr", CommandFlags. Session)]
Public void SetBkGroundColor ()
{
// Access the Preferences object
AcadPreferences acPrefComObj = (AcadPreferences) Application. Preferences;
// Use the CursorSize property to set the size of the crosshairs
AcPrefComObj. Display. CursorSize = 100;
System. Drawing. Color bkClr = Color. FromArgb (0,255,255,255); // white, do not use known color, use Argb instead.
// AcPrefComObj. Display. GraphicsWinLayoutBackgrndColor = ColorToUInt (bkClr );
AcPrefComObj. Display. GraphicsWinModelBackgrndColor = ColorToUInt (bkClr );
}
Private uint ColorToUInt (Color color)
{
Return (uint) (color. A <24) | (color. R <16) |
(Color. G <8) | (color. B <0 ));
}
Private System. Drawing. Color UIntToColor (uint color)
{
Byte a = (byte) (color> 24 );
Byte r = (byte) (color> 16 );
Byte g = (byte) (color> 8 );
Byte B = (byte) (color> 0 );
Return Color. FromArgb (a, r, g, B );
}
Where the conversion function comes from the http://www.daniweb.com/software-development/csharp/code/217202