ToolStripItemRenderEventArgs ToolStripItemRenderEventArgs ToolStripItemRenderEventArgs ToolStripItemRenderEventArgs Class

정의

ToolStripItem 클래스의 ToolStripRenderer에서 파생된 개체의 배경을 렌더링하는 이벤트에 대한 데이터를 제공합니다.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
상속
ToolStripItemRenderEventArgsToolStripItemRenderEventArgsToolStripItemRenderEventArgsToolStripItemRenderEventArgs
파생

예제

다음 코드 예제에서는 재정의 하는 방법에 설명 합니다 OnRenderButtonBackground 주위에 테두리를 그리는 방법을 ToolStripButton 컨트롤의 Image합니다.The following code example demonstrates how to override the OnRenderButtonBackground method to draw a border around a ToolStripButton control's Image. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ToolStripRenderer 클래스입니다.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

설명

ToolStripItemRenderEventArgs 클래스는 다음과 같은 이벤트에 대 한 데이터를 제공 합니다.The ToolStripItemRenderEventArgs class provides data for the following events:

또한 다음 메서드에 대 한 데이터를 제공 합니다.In addition, it provides data for the following methods:

생성자

ToolStripItemRenderEventArgs(Graphics, ToolStripItem) ToolStripItemRenderEventArgs(Graphics, ToolStripItem) ToolStripItemRenderEventArgs(Graphics, ToolStripItem) ToolStripItemRenderEventArgs(Graphics, ToolStripItem)

지정된 ToolStripItemRenderEventArgs를 사용하여 지정된 ToolStripItem에 대해 Graphics 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ToolStripItemRenderEventArgs class for the specified ToolStripItem and using the specified Graphics.

속성

Graphics Graphics Graphics Graphics

ToolStripItem을 그리는 데 사용되는 그래픽을 가져옵니다.Gets the graphics used to paint the ToolStripItem.

Item Item Item Item

그릴 ToolStripItem을 가져옵니다.Gets the ToolStripItem to paint.

ToolStrip ToolStrip ToolStrip ToolStrip

그릴 OwnerToolStripItem 속성 값을 가져옵니다.Gets the value of the Owner property for the ToolStripItem to paint.

메서드

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

적용 대상

추가 정보