ToolStripItemRenderEventArgs Klasse

Definition

Stellt Daten für Ereignisse bereit, die den Hintergrund der vom ToolStripItem in der ToolStripRenderer-Klasse abgeleiteten Objekte rendern.Provides data for the events that render the background of objects derived from ToolStripItem in the ToolStripRenderer class.

public ref class ToolStripItemRenderEventArgs : EventArgs
public class ToolStripItemRenderEventArgs : EventArgs
type ToolStripItemRenderEventArgs = class
    inherit EventArgs
Public Class ToolStripItemRenderEventArgs
Inherits EventArgs
Vererbung
ToolStripItemRenderEventArgs
Abgeleitet

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die OnRenderButtonBackground -Methode überschrieben wird, um ToolStripButton einen Rahmen Imageum die eines-Steuer Elements zu zeichnen.The following code example demonstrates how to override the OnRenderButtonBackground method to draw a border around a ToolStripButton control's Image. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die ToolStripRenderer -Klasse bereitgestellt wird.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 override void OnRenderButtonBackground(
    ToolStripItemRenderEventArgs e)
{
    base.OnRenderButtonBackground(e);

    // Define some local variables for convenience.
    Graphics g = e.Graphics;
    GridStrip gs = e.ToolStrip as GridStrip;
    ToolStripButton gsb = e.Item as ToolStripButton;

    // Calculate the rectangle around which the border is painted.
    Rectangle imageRectangle = 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 == gs.EmptyCell)
    {
        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.
        Brush b = gs.IsValidDragSource(gsb) ? b = 
            Brushes.Red : SystemBrushes.ControlDarkDark;

        // Draw the top segment of the border.
        Rectangle borderSegment = 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);
    }
}
  ' 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

Hinweise

Die ToolStripItemRenderEventArgs -Klasse stellt Daten für die folgenden Ereignisse bereit:The ToolStripItemRenderEventArgs class provides data for the following events:

Außerdem werden Daten für die folgenden Methoden bereitstellen:In addition, it provides data for the following methods:

Konstruktoren

ToolStripItemRenderEventArgs(Graphics, ToolStripItem)

Initialisiert eine neue Instanz der ToolStripItemRenderEventArgs-Klasse des angegebenen ToolStripItem unter Verwendung der angegebenen Instanz von Graphics.Initializes a new instance of the ToolStripItemRenderEventArgs class for the specified ToolStripItem and using the specified Graphics.

Eigenschaften

Graphics

Ruft die zum Zeichnen des ToolStripItem verwendete Grafik ab.Gets the graphics used to paint the ToolStripItem.

Item

Ruft den zu zeichnenden ToolStripItem ab.Gets the ToolStripItem to paint.

ToolStrip

Ruft den Wert der Owner-Eigenschaft für das zu zeichnende ToolStripItem ab.Gets the value of the Owner property for the ToolStripItem to paint.

Methoden

Equals(Object)

Ermittelt, ob das angegebene Objekt und das aktuelle Objekt gleich sind.Determines whether the specified object is equal to the current object.

(Geerbt von Object)
GetHashCode()

Dient als die Standard-HashfunktionServes as the default hash function.

(Geerbt von Object)
GetType()

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object.

(Geerbt von Object)

Gilt für:

Siehe auch