ToolStripItemRenderEventArgs 클래스

정의

ToolStripItem 클래스의 ToolStripRenderer에서 파생된 개체의 배경을 렌더링하는 이벤트에 대한 데이터를 제공합니다.

public ref class ToolStripItemRenderEventArgs : EventArgs
public class ToolStripItemRenderEventArgs : EventArgs
type ToolStripItemRenderEventArgs = class
    inherit EventArgs
Public Class ToolStripItemRenderEventArgs
Inherits EventArgs
상속
ToolStripItemRenderEventArgs
파생

예제

다음 코드 예제에서는 재정의 하는 방법에 설명 합니다 OnRenderButtonBackground 주위에 테두리를 그리는 방법을 ToolStripButton 컨트롤의 Image합니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ToolStripRenderer 클래스입니다.

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

설명

ToolStripItemRenderEventArgs 클래스는 다음과 같은 이벤트에 대 한 데이터를 제공 합니다.

또한 다음 메서드에 대 한 데이터를 제공 합니다.

생성자

ToolStripItemRenderEventArgs(Graphics, ToolStripItem)

지정된 ToolStripItemRenderEventArgs를 사용하여 지정된 ToolStripItem에 대해 Graphics 클래스의 새 인스턴스를 초기화합니다.

속성

Graphics

ToolStripItem을 그리는 데 사용되는 그래픽을 가져옵니다.

Item

그릴 ToolStripItem을 가져옵니다.

ToolStrip

그릴 OwnerToolStripItem 속성 값을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보