ToolStripProfessionalRenderer Class

 

Handles the painting functionality for ToolStrip objects, applying a custom palette and a streamlined style.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

System.Object
  System.Windows.Forms.ToolStripRenderer
    System.Windows.Forms.ToolStripProfessionalRenderer

Public Class ToolStripProfessionalRenderer
	Inherits ToolStripRenderer

NameDescription
System_CAPS_pubmethodToolStripProfessionalRenderer()

Initializes a new instance of the ToolStripProfessionalRenderer class.

System_CAPS_pubmethodToolStripProfessionalRenderer(ProfessionalColorTable)

Initializes a new instance of the ToolStripProfessionalRenderer class.

NameDescription
System_CAPS_pubpropertyColorTable

Gets the color palette used for painting.

System_CAPS_pubpropertyRoundedEdges

Gets or sets a value indicating whether edges of controls have a rounded rather than a square or sharp appearance.

NameDescription
System_CAPS_pubmethodDrawArrow(ToolStripArrowRenderEventArgs)

Draws an arrow on a ToolStripItem.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawButtonBackground(ToolStripItemRenderEventArgs)

Draws the background for a ToolStripButton.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawDropDownButtonBackground(ToolStripItemRenderEventArgs)

Draws the background for a ToolStripDropDownButton.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawGrip(ToolStripGripRenderEventArgs)

Draws a move handle on a ToolStrip.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawImageMargin(ToolStripRenderEventArgs)

Draws the space around an image on a ToolStrip.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawItemBackground(ToolStripItemRenderEventArgs)

Draws the background for a ToolStripItem.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawItemCheck(ToolStripItemImageRenderEventArgs)

Draws an image on a ToolStripItem that indicates the item is in a selected state.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawItemImage(ToolStripItemImageRenderEventArgs)

Draws an image on a ToolStripItem.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawItemText(ToolStripItemTextRenderEventArgs)

Draws text on a ToolStripItem.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawLabelBackground(ToolStripItemRenderEventArgs)

Draws the background for a ToolStripLabel.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawMenuItemBackground(ToolStripItemRenderEventArgs)

Draws the background for a ToolStripMenuItem.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawOverflowButtonBackground(ToolStripItemRenderEventArgs)

Draws the background for an overflow button.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawSeparator(ToolStripSeparatorRenderEventArgs)

Draws a ToolStripSeparator.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawSplitButton(ToolStripItemRenderEventArgs)

Draws a ToolStripSplitButton.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawStatusStripSizingGrip(ToolStripRenderEventArgs)

Draws a sizing grip.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawToolStripBackground(ToolStripRenderEventArgs)

Draws the background for a ToolStrip.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawToolStripBorder(ToolStripRenderEventArgs)

Draws the border for a ToolStrip.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawToolStripContentPanelBackground(ToolStripContentPanelRenderEventArgs)

Draws the background of the ToolStripContentPanel.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawToolStripPanelBackground(ToolStripPanelRenderEventArgs)

Draws the background of the ToolStripPanel.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodDrawToolStripStatusLabelBackground(ToolStripItemRenderEventArgs)

Draws the background of the ToolStripStatusLabel.(Inherited from ToolStripRenderer.)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodInitialize(ToolStrip)

When overridden in a derived class, provides for custom initialization of the given ToolStrip. (Inherited from ToolStripRenderer.)

System_CAPS_protmethodInitializeContentPanel(ToolStripContentPanel)

Initializes the specified ToolStripContentPanel.(Inherited from ToolStripRenderer.)

System_CAPS_protmethodInitializeItem(ToolStripItem)

When overridden in a derived class, provides for custom initialization of the given ToolStripItem. (Inherited from ToolStripRenderer.)

System_CAPS_protmethodInitializePanel(ToolStripPanel)

Initializes the specified ToolStripPanel.(Inherited from ToolStripRenderer.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodOnRenderArrow(ToolStripArrowRenderEventArgs)
System_CAPS_protmethodOnRenderButtonBackground(ToolStripItemRenderEventArgs)
System_CAPS_protmethodOnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs)
System_CAPS_protmethodOnRenderGrip(ToolStripGripRenderEventArgs)
System_CAPS_protmethodOnRenderImageMargin(ToolStripRenderEventArgs)
System_CAPS_protmethodOnRenderItemBackground(ToolStripItemRenderEventArgs)

Raises the OnRenderItemBackground event. (Inherited from ToolStripRenderer.)

System_CAPS_protmethodOnRenderItemCheck(ToolStripItemImageRenderEventArgs)
System_CAPS_protmethodOnRenderItemImage(ToolStripItemImageRenderEventArgs)
System_CAPS_protmethodOnRenderItemText(ToolStripItemTextRenderEventArgs)
System_CAPS_protmethodOnRenderLabelBackground(ToolStripItemRenderEventArgs)
System_CAPS_protmethodOnRenderMenuItemBackground(ToolStripItemRenderEventArgs)
System_CAPS_protmethodOnRenderOverflowButtonBackground(ToolStripItemRenderEventArgs)
System_CAPS_protmethodOnRenderSeparator(ToolStripSeparatorRenderEventArgs)
System_CAPS_protmethodOnRenderSplitButtonBackground(ToolStripItemRenderEventArgs)

Raises the OnRenderSplitButtonBackground event.(Overrides ToolStripRenderer.OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs).)

System_CAPS_protmethodOnRenderStatusStripSizingGrip(ToolStripRenderEventArgs)

Raises the RenderStatusStripSizingGrip event.(Inherited from ToolStripRenderer.)

System_CAPS_protmethodOnRenderToolStripBackground(ToolStripRenderEventArgs)
System_CAPS_protmethodOnRenderToolStripBorder(ToolStripRenderEventArgs)
System_CAPS_protmethodOnRenderToolStripContentPanelBackground(ToolStripContentPanelRenderEventArgs)
System_CAPS_protmethodOnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs)
System_CAPS_protmethodOnRenderToolStripStatusLabelBackground(ToolStripItemRenderEventArgs)
System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubeventRenderArrow

Occurs when an arrow on a ToolStripItem is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderButtonBackground

Occurs when the background for a ToolStripButton is rendered(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderDropDownButtonBackground

Occurs when the background for a ToolStripDropDownButton is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderGrip

Occurs when the move handle for a ToolStrip is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderImageMargin

Draws the margin between an image and its container. (Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderItemBackground

Occurs when the background for a ToolStripItem is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderItemCheck

Occurs when the image for a selected ToolStripItem is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderItemImage

Occurs when the image for a ToolStripItem is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderItemText

Occurs when the text for a ToolStripItem is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderLabelBackground

Occurs when the background for a ToolStripLabel is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderMenuItemBackground

Occurs when the background for a ToolStripMenuItem is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderOverflowButtonBackground

Occurs when the background for an overflow button is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderSeparator

Occurs when a ToolStripSeparator is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderSplitButtonBackground

Occurs when the background for a ToolStripSplitButton is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderStatusStripSizingGrip

Occurs when the display style changes.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderToolStripBackground

Occurs when the background for a ToolStrip is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderToolStripBorder

Occurs when the border for a ToolStrip is rendered.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderToolStripContentPanelBackground

Draws the background of a ToolStripContentPanel.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderToolStripPanelBackground

Draws the background of a ToolStripPanel.(Inherited from ToolStripRenderer.)

System_CAPS_pubeventRenderToolStripStatusLabelBackground

Draws the background of a ToolStripStatusLabel.(Inherited from ToolStripRenderer.)

ToolStripProfessionalRenderer creates pens and brushes based on a replaceable color table called ProfessionalColorTable.

The following code example demonstrates how to create a composite control that mimics the Navigation Pane provided by Microsoft® Outlook®. For a full code listing, see How to: Create a Professionally Styled ToolStrip Control.

Friend Class StackRenderer
   Inherits ToolStripProfessionalRenderer
   Private Shared titleBarGripBmp As Bitmap
   Private Shared titleBarGripEnc As String = "Qk16AQAAAAAAADYAAAAoAAAAIwAAAAMAAAABABgAAAAAAAAAAADEDgAAxA4AAAAAAAAAAAAAuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5uGMyuGMy+/n5+/n5ANj+RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5wm8/RzIomHRh+/n5ANj+RzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMzHtMRzIoRzIozHtMANj+"

   ' Define titlebar colors.
   Private Shared titlebarColor1 As Color = Color.FromArgb(89, 135, 214)
   Private Shared titlebarColor2 As Color = Color.FromArgb(76, 123, 204)
   Private Shared titlebarColor3 As Color = Color.FromArgb(63, 111, 194)
   Private Shared titlebarColor4 As Color = Color.FromArgb(50, 99, 184)
   Private Shared titlebarColor5 As Color = Color.FromArgb(38, 88, 174)
   Private Shared titlebarColor6 As Color = Color.FromArgb(25, 76, 164)
   Private Shared titlebarColor7 As Color = Color.FromArgb(12, 64, 154)
   Private Shared borderColor As Color = Color.FromArgb(0, 0, 128)

   Shared Sub New()
      titleBarGripBmp = StackView.DeserializeFromBase64(titleBarGripEnc)
     End Sub

   Public Sub New()
     End Sub

     Private Sub DrawTitleBar(ByVal g As Graphics, ByVal rect As Rectangle)

         ' Assign the image for the grip.
         Dim titlebarGrip As Image = titleBarGripBmp

         ' Fill the titlebar. 
         ' This produces the gradient and the rounded-corner effect.
         g.DrawLine(New Pen(titlebarColor1), rect.X, rect.Y, rect.X + rect.Width, rect.Y)
         g.DrawLine(New Pen(titlebarColor2), rect.X, rect.Y + 1, rect.X + rect.Width, rect.Y + 1)
         g.DrawLine(New Pen(titlebarColor3), rect.X, rect.Y + 2, rect.X + rect.Width, rect.Y + 2)
         g.DrawLine(New Pen(titlebarColor4), rect.X, rect.Y + 3, rect.X + rect.Width, rect.Y + 3)
         g.DrawLine(New Pen(titlebarColor5), rect.X, rect.Y + 4, rect.X + rect.Width, rect.Y + 4)
         g.DrawLine(New Pen(titlebarColor6), rect.X, rect.Y + 5, rect.X + rect.Width, rect.Y + 5)
         g.DrawLine(New Pen(titlebarColor7), rect.X, rect.Y + 6, rect.X + rect.Width, rect.Y + 6)

         ' Center the titlebar grip.
         g.DrawImage(titlebarGrip, New Point(rect.X + (rect.Width / 2 - titlebarGrip.Width / 2), rect.Y + 1))
     End Sub


   ' This method handles the RenderGrip event.
   Protected Overrides Sub OnRenderGrip(e As ToolStripGripRenderEventArgs)
      DrawTitleBar(e.Graphics, New Rectangle(0, 0, e.ToolStrip.Width, 7))
     End Sub


   ' This method handles the RenderToolStripBorder event.
   Protected Overrides Sub OnRenderToolStripBorder(e As ToolStripRenderEventArgs)
      DrawTitleBar(e.Graphics, New Rectangle(0, 0, e.ToolStrip.Width, 7))
     End Sub


   ' This method handles the RenderButtonBackground event.
   Protected Overrides Sub OnRenderButtonBackground(e As ToolStripItemRenderEventArgs)
      Dim g As Graphics = e.Graphics
      Dim bounds As New Rectangle(Point.Empty, e.Item.Size)

      Dim gradientBegin As Color = Color.FromArgb(203, 225, 252)
      Dim gradientEnd As Color = Color.FromArgb(125, 165, 224)

         Dim button As ToolStripButton = CType(e.Item, ToolStripButton)

      If button.Pressed OrElse button.Checked Then
         gradientBegin = Color.FromArgb(254, 128, 62)
         gradientEnd = Color.FromArgb(255, 223, 154)
      ElseIf button.Selected Then
         gradientBegin = Color.FromArgb(255, 255, 222)
         gradientEnd = Color.FromArgb(255, 203, 136)
      End If

      Dim b = New LinearGradientBrush(bounds, gradientBegin, gradientEnd, LinearGradientMode.Vertical)
      Try
         g.FillRectangle(b, bounds)
      Finally
         b.Dispose()
      End Try

      e.Graphics.DrawRectangle(SystemPens.ControlDarkDark, bounds)

      g.DrawLine(SystemPens.ControlDarkDark, bounds.X, bounds.Y, bounds.Width - 1, bounds.Y)

      g.DrawLine(SystemPens.ControlDarkDark, bounds.X, bounds.Y, bounds.X, bounds.Height - 1)

      Dim toolStrip As ToolStrip = button.Owner
         Dim nextItem As ToolStripButton = CType(button.Owner.GetItemAt(button.Bounds.X, button.Bounds.Bottom + 1), ToolStripButton)

      If nextItem Is Nothing Then
         g.DrawLine(SystemPens.ControlDarkDark, bounds.X, bounds.Height - 1, bounds.X + bounds.Width - 1, bounds.Height - 1)
      End If
     End Sub
 End Class

.NET Framework
Available since 2.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: