Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
How to: Customize Colors in ToolStrip Applications
Collapse the table of content
Expand the table of content

How to: Customize Colors in ToolStrip Applications

You can customize the appearance of your ToolStrip by using the ToolStripProfessionalRenderer class to use customized colors.

The following code example demonstrates how to use a ToolStripProfessionalRenderer to define custom colors at run time.

// This code example demonstrates how to use a ProfessionalRenderer 
// to define custom professional colors at runtime. 
class Form2 : Form
    public Form2()
        // Create a new ToolStrip control.
        ToolStrip ts = new ToolStrip();

        // Populate the ToolStrip control.
            "Change Colors", 
            new EventHandler(ChangeColors_Click));

        // Create a new MenuStrip.
        MenuStrip ms = new MenuStrip();

        // Dock the MenuStrip control to the top of the form.
        ms.Dock = DockStyle.Top;

        // Add the top-level menu items.

        // Add the ToolStrip to Controls collection. 

        // Add the MenuStrip control last. 
        // This is important for correct placement in the z-order. 

    // This event handler is invoked when the "Change colors" 
    // ToolStripItem is clicked. It assigns the Renderer 
    // property for the ToolStrip control. 
    void ChangeColors_Click(object sender, EventArgs e)
        ToolStripManager.Renderer = 
            new ToolStripProfessionalRenderer(new CustomProfessionalColors());

// This class defines the gradient colors for  
// the MenuStrip and the ToolStrip. 
class CustomProfessionalColors : ProfessionalColorTable
    public override Color ToolStripGradientBegin
    { get { return Color.BlueViolet; } }

    public override Color ToolStripGradientMiddle
    { get { return Color.CadetBlue; } }

    public override Color ToolStripGradientEnd
    { get { return Color.CornflowerBlue; } }

    public override Color MenuStripGradientBegin
    { get { return Color.Salmon; } }

    public override Color MenuStripGradientEnd
    { get { return Color.OrangeRed; } }

This example requires:

  • References to the System.Design, System.Drawing, and System.Windows.Forms assemblies.

For information about building this example from the command line for Visual Basic or Visual C#, see Building from the Command Line (Visual Basic) or Command-line Building With csc.exe. You can also build this example in Visual Studio by pasting the code into a new project. Also see How to: Compile and Run a Complete Windows Forms Code Example Using Visual Studio.

© 2015 Microsoft