Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-custom-draw-a-toolstrip-control.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

5.7 KiB
Raw Blame History

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Custom Draw a ToolStrip Control 03/30/2017
csharp
vb
toolbars [Windows Forms], custom drawing
drawing [Windows Forms], owner
ProfessionalColorTable class [Windows Forms], overriding
examples [Windows Forms], toolbars
drawing [Windows Forms], custom
toolbars [Windows Forms], changing colors
ToolStrip control [Windows Forms], drawing
ToolStrip control [Windows Forms], changing colors
custom drawing
owner drawing
94e7d7bd-a752-441c-b5b3-7acf98881163

How to: Custom Draw a ToolStrip Control

The xref:System.Windows.Forms.ToolStrip controls have the following associated rendering (painting) classes:

To custom draw (also known as owner draw) a xref:System.Windows.Forms.ToolStrip, you can override one of the renderer classes and change an aspect of the rendering logic.

The following procedures describe various aspects of custom drawing.

To switch between the provided renderers

To change the Microsoft Officestyle borders to straight

Note

There is a version of this method for xref:System.Windows.Forms.ToolStripRenderer, xref:System.Windows.Forms.ToolStripSystemRenderer, and xref:System.Windows.Forms.ToolStripProfessionalRenderer.

To change the ProfessionalColorTable

  • Override xref:System.Windows.Forms.ProfessionalColorTable and change the colors you want.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _  
    System.EventArgs) Handles Me.Load  
        Dim t As MyColorTable = New MyColorTable  
        ToolStrip1.Renderer = New ToolStripProfessionalRenderer(t)  
    End Sub  
    
    Class MyColorTable
    Inherits ProfessionalColorTable  
    
    Public Overrides ReadOnly Property ButtonPressedGradientBegin() As Color  
        Get  
            Return Color.Red  
        End Get  
    End Property  
    
    Public Overrides ReadOnly Property ButtonPressedGradientMiddle() _  
    As System.Drawing.Color  
        Get  
            Return Color.Blue  
        End Get  
            End Property  
    
    Public Overrides ReadOnly Property ButtonPressedGradientEnd() _  
    As System.Drawing.Color  
        Get  
            Return Color.Green  
        End Get  
    End Property  
    
    Public Overrides ReadOnly Property ButtonSelectedGradientBegin() _  
    As Color  
        Get  
            Return Color.Yellow  
        End Get  
    End Property  
    
    Public Overrides ReadOnly Property ButtonSelectedGradientMiddle() As System.Drawing.Color  
        Get  
            Return Color.Orange  
        End Get  
    End Property  
    
    Public Overrides ReadOnly Property ButtonSelectedGradientEnd() _  
    As System.Drawing.Color  
        Get  
            Return Color.Violet  
        End Get  
    End Property  
    End Class  
    

To change the rendering for all ToolStrip controls in your application

  1. Use the xref:System.Windows.Forms.ToolStripManager.RenderMode%2A?displayProperty=nameWithType property to choose one of the provided renderers.

  2. Use xref:System.Windows.Forms.ToolStripManager.Renderer%2A?displayProperty=nameWithType to assign a custom renderer.

  3. Ensure that xref:System.Windows.Forms.ToolStrip.RenderMode%2A?displayProperty=nameWithType is set to the default value of xref:System.Windows.Forms.ToolStripRenderMode.ManagerRenderMode.

To turn off the Microsoft Office colors for the entire application

To turn off the Microsoft Office colors for one ToolStrip control

  • Use code similar to the following code example.

    Dim colorTable As ProfessionalColorTable()  
    colorTable.UseSystemColors = True  
    Dim toolStrip.Renderer As ToolStripProfessionalRenderer(colorTable)  
    
    ProfessionalColorTable colorTable = new ProfessionalColorTable();  
    colorTable.UseSystemColors = true;  
    toolStrip.Renderer = new ToolStripProfessionalRenderer(colorTable);  
    

See also