This documentation is archived and is not being maintained.

ToolStripItemRenderEventArgs Class

Provides data for the events that render the background of objects derived from ToolStripItem in the ToolStripRenderer class.

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

'Declaration
Public Class ToolStripItemRenderEventArgs _
	Inherits EventArgs
'Usage
Dim instance As ToolStripItemRenderEventArgs

The following code example demonstrates how to override the OnRenderButtonBackground method to draw a border around a ToolStripButton control's Image. This code example is part of a larger example provided for the ToolStripRenderer class.

  ' This method draws a border around the button's image. If the background 
  ' to be rendered belongs to the empty cell, a string is drawn. Otherwise, 
  ' a border is drawn at the edges of the button. 
  Protected Overrides Sub OnRenderButtonBackground(e As ToolStripItemRenderEventArgs)
     MyBase.OnRenderButtonBackground(e)

     ' Define some local variables for convenience. 
     Dim g As Graphics = e.Graphics
     Dim gs As GridStrip = e.ToolStrip 
     Dim gsb As ToolStripButton = e.Item 

     ' Calculate the rectangle around which the border is painted. 
     Dim imageRectangle As New Rectangle(borderThickness, borderThickness, e.Item.Width - 2 * borderThickness, e.Item.Height - 2 * borderThickness)

     ' If rendering the empty cell background, draw an  
     ' explanatory string, centered in the ToolStripButton. 
        If gsb Is gs.EmptyCell Then
            e.Graphics.DrawString("Drag to here", gsb.Font, SystemBrushes.ControlDarkDark, imageRectangle, style)
        Else 
            ' If the button can be a drag source, paint its border red. 
            ' otherwise, paint its border a dark color. 
            Dim b As Brush = IIf(gs.IsValidDragSource(gsb), Brushes.Red, SystemBrushes.ControlDarkDark)

            ' Draw the top segment of the border. 
            Dim borderSegment As New Rectangle(0, 0, e.Item.Width, imageRectangle.Top)
            g.FillRectangle(b, borderSegment)

            ' Draw the right segment.
            borderSegment = New Rectangle(imageRectangle.Right, 0, e.Item.Bounds.Right - imageRectangle.Right, imageRectangle.Bottom)
            g.FillRectangle(b, borderSegment)

            ' Draw the left segment.
            borderSegment = New Rectangle(0, 0, imageRectangle.Left, e.Item.Height)
            g.FillRectangle(b, borderSegment)

            ' Draw the bottom segment.
            borderSegment = New Rectangle(0, imageRectangle.Bottom, e.Item.Width, e.Item.Bounds.Bottom - imageRectangle.Bottom)
            g.FillRectangle(b, borderSegment)
        End If 
    End Sub 
End Class

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: