Permalink
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (53 sloc) 4.1 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
How to: Set the ToolStrip Renderer at Run Time
03/30/2017
.net-framework
dotnet-winforms
article
jsharp
toolbars [Windows Forms]
ToolStripManager class [Windows Forms]
ToolStripProfessionalRenderer class [Windows Forms]
ToolStrip control [Windows Forms]
MenuStrip control [Windows Forms]
525e2347-0804-49aa-b9a3-9b2cabbf1c35
11
dotnet-bot
dotnetcontent
wpickett

How to: Set the ToolStrip Renderer at Run Time

You can customize the appearance of your xref:System.Windows.Forms.ToolStrip control by creating a custom ProfessionalColorTable class.

Example

The following code example demonstrates how to create a custom ProfessionalColorTable class. This class defines gradients for a xref:System.Windows.Forms.MenuStrip and a xref:System.Windows.Forms.ToolStrip control.

To use this code example, compile and run the application, and then click Change Colors to apply the gradients defined in the custom ProfessionalColorTable class.

[!code-csharpSystem.Windows.Forms.ToolStrip.Misc#1] [!code-vbSystem.Windows.Forms.ToolStrip.Misc#1]
[!code-csharpSystem.Windows.Forms.ToolStrip.Misc#20] [!code-vbSystem.Windows.Forms.ToolStrip.Misc#20]

Defining a Custom ProfessionalColorTable class

The custom gradients are defined in the CustomProfessionalColors class.

[!code-csharpSystem.Windows.Forms.ToolStrip.Misc#30] [!code-vbSystem.Windows.Forms.ToolStrip.Misc#30]

Assigning a Custom Renderer

Create a new ToolStripProfessionalRenderer with a CustomProfessionalColors class, and assign it to the xref:System.Windows.Forms.ToolStripManager.Renderer%2A?displayProperty=nameWithType property.

[!code-csharpSystem.Windows.Forms.ToolStrip.Misc#22] [!code-vbSystem.Windows.Forms.ToolStrip.Misc#22]

Compiling the Code

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 [!INCLUDEvbprvb] or [!INCLUDEcsprcs], see Building from the Command Line or Command-line Building With csc.exe. You can also build this example in [!INCLUDEvsprvs] by pasting the code into a new project. Also see How to: Compile and Run a Complete Windows Forms Code Example Using Visual Studio.

See Also

xref:System.Windows.Forms.ToolStripManager
xref:System.Windows.Forms.ProfessionalColorTable
xref:System.Windows.Forms.MenuStrip
xref:System.Windows.Forms.ToolStrip
xref:System.Windows.Forms.ToolStripProfessionalRenderer
ToolStrip Control