Hide Table of Contents

Change Colors of User-interface Elements Example (C#)

This example shows how to change the colors of user-interface elements.

//--------------------------------------------------------------
// Preconditions:
// 1. Create a C# Windows console project.
// 2. Copy and paste this example into the C# IDE.
// 3. Add a reference to:
//    install_dir\APISDK\tlb\DraftSight.Interop.dsAutomation.dll.
// 4. Add references to System and System.Windows.Forms.
// 5. Start DraftSight and open a document.
// 6. Start debugging the project.
//
// Postconditions: 
// 1. Message boxes pop up before and after the colors of
//    the user-interface elements change. 
// 2. Click OK to close each message box.
// 3. Examine and experiment with the user-interface 
//    elements whose colors changed:
//    * Text in command window
//    * Crosshair
//    * Background of model
// 4. Run the macro again to reset the colors of the user-interface
//    elements to their former colors.
//----------------------------------------------------------------
 
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using DraftSight.Interop.dsAutomation;
 
namespace ApplicationOptionsCSharp
{
 
    static class Program
    {
        public static void Main(string[] args)
        {
            DraftSight.Interop.dsAutomation.Application dsApp;
 
            //Connect to DraftSight application
            dsApp = (DraftSight.Interop.dsAutomation.Application)Marshal.GetActiveObject("DraftSight.Application");

            // Abort any command currently running in DraftSight to avoid nested commands
            dsApp.AbortRunningCommand();

            if (null == dsApp)
            {
                return;
            }
 
            ApplicationOptions dsApplicationOptions = dsApp.GetApplicationOptions();
 
            //Change colors of user-interface elements
 
            //Set color of text of command window to blue or black, dependent on current color
            Color dsColor = dsApplicationOptions.GetElementColor(dsElementColor_e.dsElementColor_CommandWindowText);
            MessageBox.Show("Color of text command window before changing its color: " + dsColor.GetNamedColor());
            if (dsColor.GetNamedColor() == dsNamedColor_e.dsNamedColor_Blue)
                dsColor.SetRGBColor(0, 0, 0);
            else
                dsColor.SetNamedColor(dsNamedColor_e.dsNamedColor_Blue);
            dsApplicationOptions.SetElementColor(dsElementColor_e.dsElementColor_CommandWindowText, dsColor);
            MessageBox.Show("Color of text of command window after changing its color: " + dsColor.GetNamedColor());
 
            //Set color of model crosshair to red or white, dependent on current color
            dsColor = dsApplicationOptions.GetElementColor(dsElementColor_e.dsElementColor_ModelCrosshair);
            MessageBox.Show("Color of crosshair before changing its color: " + dsColor.GetNamedColor());
            if (dsColor.GetNamedColor() == dsNamedColor_e.dsNamedColor_Red)
                dsColor.SetNamedColor(dsNamedColor_e.dsNamedColor_White);
            else
                dsColor.SetNamedColor(dsNamedColor_e.dsNamedColor_Red);
            dsApplicationOptions.SetElementColor(dsElementColor_e.dsElementColor_ModelCrosshair, dsColor);
            MessageBox.Show("Color of crosshair after changing its color: " + dsColor.GetNamedColor());
 
            //Set color of background of model to white or black, dependent on current color
            dsColor = dsApplicationOptions.GetElementColor(dsElementColor_e.dsElementColor_ModelBackground);
            MessageBox.Show("Color of model background before changing its color: " + dsColor.GetNamedColor());
            if (dsColor.GetNamedColor() == dsNamedColor_e.dsNamedColor_White)
                dsColor.SetRGBColor(0, 0, 0);
            else
                dsColor.SetNamedColor(dsNamedColor_e.dsNamedColor_White);
            dsApplicationOptions.SetElementColor(dsElementColor_e.dsElementColor_ModelBackground, dsColor);
            MessageBox.Show("Color of model background after changing its color: " + dsColor.GetNamedColor());
 
        }
    }
}


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Change Colors of User-interface Elements Example (C#)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2019 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.