ToolStripItemRenderEventArgs Klasa

Definicja

Dostarcza dane dla zdarzeń renderujących tło obiektów pochodzących z ToolStripItem klasy ToolStripRenderer .

public ref class ToolStripItemRenderEventArgs : EventArgs
public class ToolStripItemRenderEventArgs : EventArgs
type ToolStripItemRenderEventArgs = class
    inherit EventArgs
Public Class ToolStripItemRenderEventArgs
Inherits EventArgs
Dziedziczenie
ToolStripItemRenderEventArgs
Pochodne

Przykłady

W poniższym przykładzie kodu pokazano, jak zastąpić metodę OnRenderButtonBackground , aby narysować obramowanie wokół ToolStripButton kontrolki Image. Ten przykład kodu jest częścią większego przykładu udostępnionego ToolStripRenderer dla klasy .

// 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

Uwagi

Klasa ToolStripItemRenderEventArgs udostępnia dane dla następujących zdarzeń:

Ponadto udostępnia dane dla następujących metod:

Konstruktory

ToolStripItemRenderEventArgs(Graphics, ToolStripItem)

Inicjuje ToolStripItemRenderEventArgs nowe wystąpienie klasy dla określonej ToolStripItem klasy i przy użyciu określonego Graphicselementu .

Właściwości

Graphics

Pobiera grafikę używaną do malowania .ToolStripItem

Item

Dostaje do ToolStripItem malowania.

ToolStrip

Pobiera wartość Owner właściwości ToolStripItem do malowania.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też