title | description | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
How to: Set the ToolStrip Renderer at Run Time |
Learn how to set the ToolStrip renderer at run time in Windows Forms, by means of code samples in C# and Visual Basic. |
03/30/2017 |
|
|
525e2347-0804-49aa-b9a3-9b2cabbf1c35 |
You can customize the appearance of your xref:System.Windows.Forms.ToolStrip control by creating a custom ProfessionalColorTable
class.
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]
The custom gradients are defined in the CustomProfessionalColors
class.
[!code-csharpSystem.Windows.Forms.ToolStrip.Misc#30] [!code-vbSystem.Windows.Forms.ToolStrip.Misc#30]
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]
This example requires:
- References to the System.Design, System.Drawing, and System.Windows.Forms assemblies.
- 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