From 1aad00b25dd1a9215f9095446e0bc87ce4d2e8cf Mon Sep 17 00:00:00 2001 From: Andy De George <67293991+adegeo@users.noreply.github.com> Date: Tue, 2 Feb 2021 13:24:37 -0800 Subject: [PATCH] Add csharp code;fix headers;bugs (#194) --- .../how-to-custom-draw-a-toolstrip-control.md | 145 ++++++++++-------- 1 file changed, 84 insertions(+), 61 deletions(-) diff --git a/dotnet-desktop-guide/framework/winforms/controls/how-to-custom-draw-a-toolstrip-control.md b/dotnet-desktop-guide/framework/winforms/controls/how-to-custom-draw-a-toolstrip-control.md index 180b465..991a33c 100644 --- a/dotnet-desktop-guide/framework/winforms/controls/how-to-custom-draw-a-toolstrip-control.md +++ b/dotnet-desktop-guide/framework/winforms/controls/how-to-custom-draw-a-toolstrip-control.md @@ -30,76 +30,99 @@ The controls have the following associated The following procedures describe various aspects of custom drawing. -### To switch between the provided renderers +## Switch between the provided renderers - Set the property to the value you want. With , the static determines the renderer for your application. The other values of are , , and . -### To change the Microsoft Office–style borders to straight +## Change the Office–style borders - Override , but do not call the base class. > [!NOTE] > There is a version of this method for , , and . -### To change the ProfessionalColorTable +## Change the ProfessionalColorTable - Override and change the colors you want. + + ```csharp + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } - ```vb - 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 + private void Form1_Load(object sender, EventArgs e) + { + var colorTable = new MyColorTable(); + toolStrip1.Renderer = new ToolStripProfessionalRenderer(colorTable); + } - Class MyColorTable - Inherits ProfessionalColorTable + class MyColorTable: ProfessionalColorTable + { + public override System.Drawing.Color ButtonPressedGradientBegin => Color.Red; + public override System.Drawing.Color ButtonPressedGradientMiddle => Color.Blue; + public override System.Drawing.Color ButtonPressedGradientEnd => Color.Green; + public override System.Drawing.Color ButtonSelectedGradientBegin => Color.Yellow; + public override System.Drawing.Color ButtonSelectedGradientMiddle => Color.Orange; + public override System.Drawing.Color ButtonSelectedGradientEnd => Color.Violet; + } + } + ``` + + ```vb + Public Class Form1 + Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load + Dim colorTable As New MyColorTable + ToolStrip1.Renderer = New ToolStripProfessionalRenderer(colorTable) + End Sub - Public Overrides ReadOnly Property ButtonPressedGradientBegin() As Color - Get - Return Color.Red - End Get - End Property + Class MyColorTable + Inherits ProfessionalColorTable - Public Overrides ReadOnly Property ButtonPressedGradientMiddle() _ - As System.Drawing.Color - Get - Return Color.Blue - End Get - End Property + Public Overrides ReadOnly Property ButtonPressedGradientBegin() As System.Drawing.Color + Get + Return Color.Red + 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 ButtonPressedGradientMiddle() As System.Drawing.Color + Get + Return Color.Blue + End Get + End Property - Public Overrides ReadOnly Property ButtonSelectedGradientBegin() _ - As Color - Get - Return Color.Yellow - 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 ButtonSelectedGradientMiddle() As System.Drawing.Color - Get - Return Color.Orange - End Get - End Property + Public Overrides ReadOnly Property ButtonSelectedGradientBegin() As System.Drawing.Color + Get + Return Color.Yellow + End Get + End Property - Public Overrides ReadOnly Property ButtonSelectedGradientEnd() _ - As System.Drawing.Color - Get - Return Color.Violet - End Get - End Property - End Class - ``` + Public Overrides ReadOnly Property ButtonSelectedGradientMiddle() As System.Drawing.Color + Get + Return Color.Orange + End Get + End Property -### To change the rendering for all ToolStrip controls in your application + Public Overrides ReadOnly Property ButtonSelectedGradientEnd() As System.Drawing.Color + Get + Return Color.Violet + End Get + End Property + End Class + End Class + ``` + +## Change rendering for all ToolStrips 1. Use the property to choose one of the provided renderers. @@ -107,25 +130,25 @@ The controls have the following associated 3. Ensure that is set to the default value of . -### To turn off the Microsoft Office colors for the entire application +## Turn off the Office colors - Set to `false`. -### To turn off the Microsoft Office colors for one ToolStrip control +## Turn off the Office colors for one ToolStrip - Use code similar to the following code example. + + ```csharp + ProfessionalColorTable colorTable = new ProfessionalColorTable(); + colorTable.UseSystemColors = true; + toolStrip1.Renderer = new ToolStripProfessionalRenderer(colorTable); + ``` - ```vb - Dim colorTable As ProfessionalColorTable() - colorTable.UseSystemColors = True - Dim toolStrip.Renderer As ToolStripProfessionalRenderer(colorTable) - ``` - - ```csharp - ProfessionalColorTable colorTable = new ProfessionalColorTable(); - colorTable.UseSystemColors = true; - toolStrip.Renderer = new ToolStripProfessionalRenderer(colorTable); - ``` + ```vb + Dim colorTable As New ProfessionalColorTable + colorTable.UseSystemColors = True + ToolStrip1.Renderer = new ToolStripProfessionalRenderer(colorTable) + ``` ## See also