Permalink
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (45 sloc) 3.35 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: Implement a Custom ToolStripRenderer
03/30/2017
.net-framework
dotnet-winforms
article
jsharp
toolbars [Windows Forms]
ToolStripRenderer class
ToolStrip control [Windows Forms]
c66fd3f7-2377-4553-8f1b-006527f08f32
9
dotnet-bot
dotnetcontent
wpickett

How to: Implement a Custom ToolStripRenderer

You can customize the appearance of a xref:System.Windows.Forms.ToolStrip control by implementing a class that derives from xref:System.Windows.Forms.ToolStripRenderer. This gives you the flexibility to create an appearance that differs from the appearance provided the xref:System.Windows.Forms.ToolStripProfessionalRenderer and xref:System.Windows.Forms.ToolStripSystemRenderer classes.

Example

The following code example demonstrates how to implement a custom xref:System.Windows.Forms.ToolStripRenderer class. In this example, the GridStrip control implements a sliding-tile puzzle, which allows the user to move tiles in a table layout to form an image. A custom xref:System.Windows.Forms.ToolStrip control arranges its xref:System.Windows.Forms.ToolStripButton controls in a grid layout. The layout contains one empty cell, into which the user can slide an adjacent tile by using a drag-and-drop operation. Tiles that the user can move are highlighted.

The GridStripRenderer class customizes three aspects of the GridStrip control's appearance:

  • GridStrip border

  • xref:System.Windows.Forms.ToolStripButton border

  • xref:System.Windows.Forms.ToolStripButton image

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

Compiling the Code

This example requires:

  • References to the 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.MenuStrip
xref:System.Windows.Forms.ToolStrip
xref:System.Windows.Forms.ToolStripRenderer
xref:System.Windows.Forms.ToolStripProfessionalRenderer
xref:System.Windows.Forms.ToolStripSystemRenderer
xref:System.Windows.Forms.StatusStrip
ToolStrip Control