다음을 통해 공유


ToolStripItem.ContentRectangle 속성

정의

배경 테두리를 덮어쓰기 않고 ToolStripItem 안에 텍스트와 아이콘 같은 내용을 배치할 수 있는 영역을 가져옵니다.

public:
 property System::Drawing::Rectangle ContentRectangle { System::Drawing::Rectangle get(); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Rectangle ContentRectangle { get; }
[<System.ComponentModel.Browsable(false)>]
member this.ContentRectangle : System.Drawing.Rectangle
Public ReadOnly Property ContentRectangle As Rectangle

속성 값

Rectangle

테두리를 제외하고 Rectangle 내용의 위치와 크기를 나타내는 정수 네 개가 포함된 ToolStripItem입니다.

특성

예제

다음 코드 예제에서는 사용자 지정 렌더링에 ContentRectangle 대 한 속성을 사용 하는 방법을 보여 줍니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ToolStripItem 클래스입니다.

// This utility method computes the layout of the 
// RolloverItem control's image area and the text area.
// For brevity, only the following settings are 
// supported:
//
// ToolStripTextDirection.Horizontal
// TextImageRelation.ImageBeforeText 
// TextImageRelation.ImageBeforeText
// 
// It would not be difficult to support vertical text
// directions and other image/text relationships.
private void ComputeImageAndTextLayout()
{
    Rectangle cr = base.ContentRectangle;
    Image img = base.Owner.ImageList.Images[base.ImageKey];

    // Compute the center of the item's ContentRectangle.
    int centerY = (cr.Height - img.Height) / 2;

    // Find the dimensions of the image and the text 
    // areas of the item. The text occupies the space 
    // not filled by the image. 
    if (base.TextImageRelation == TextImageRelation.ImageBeforeText &&
        base.TextDirection == ToolStripTextDirection.Horizontal)
    {
        imageRect = new Rectangle(
            base.ContentRectangle.Left,
            centerY,
            base.Image.Width,
            base.Image.Height);

        textRect = new Rectangle(
            imageRect.Width,
            base.ContentRectangle.Top,
            base.ContentRectangle.Width - imageRect.Width,
            base.ContentRectangle.Height);
    }
    else if (base.TextImageRelation == TextImageRelation.TextBeforeImage &&
             base.TextDirection == ToolStripTextDirection.Horizontal)
    {
        imageRect = new Rectangle(
            base.ContentRectangle.Right - base.Image.Width,
            centerY,
            base.Image.Width,
            base.Image.Height);

        textRect = new Rectangle(
            base.ContentRectangle.Left,
            base.ContentRectangle.Top,
            imageRect.X,
            base.ContentRectangle.Bottom);
    }
}
   ' This utility method computes the layout of the 
   ' RolloverItem control's image area and the text area.
   ' For brevity, only the following settings are 
   ' supported:
   '
   ' ToolStripTextDirection.Horizontal
   ' TextImageRelation.ImageBeforeText 
   ' TextImageRelation.ImageBeforeText
   ' 
   ' It would not be difficult to support vertical text
   ' directions and other image/text relationships.
   Private Sub ComputeImageAndTextLayout()
      Dim cr As Rectangle = MyBase.ContentRectangle
      Dim img As Image = MyBase.Owner.ImageList.Images(MyBase.ImageKey)
      
      ' Compute the center of the item's ContentRectangle.
        Dim centerY As Integer = CInt((cr.Height - img.Height) / 2)
      
      ' Find the dimensions of the image and the text 
      ' areas of the item. The text occupies the space 
      ' not filled by the image. 
        If MyBase.TextImageRelation = _
        TextImageRelation.ImageBeforeText AndAlso _
        MyBase.TextDirection = ToolStripTextDirection.Horizontal Then

            imageRect = New Rectangle( _
            MyBase.ContentRectangle.Left, _
            centerY, _
            MyBase.Image.Width, _
            MyBase.Image.Height)

            textRect = New Rectangle( _
            imageRect.Width, _
            MyBase.ContentRectangle.Top, _
            MyBase.ContentRectangle.Width - imageRect.Width, _
            MyBase.ContentRectangle.Height)

        ElseIf MyBase.TextImageRelation = _
        TextImageRelation.TextBeforeImage AndAlso _
        MyBase.TextDirection = ToolStripTextDirection.Horizontal Then

            imageRect = New Rectangle( _
            MyBase.ContentRectangle.Right - MyBase.Image.Width, _
            centerY, _
            MyBase.Image.Width, _
            MyBase.Image.Height)

            textRect = New Rectangle( _
            MyBase.ContentRectangle.Left, _
            MyBase.ContentRectangle.Top, _
            imageRect.X, _
            MyBase.ContentRectangle.Bottom)

        End If
    End Sub
End Class

설명

속성을 ContentRectangle 사용하여 .의 사용자 지정 그리기를 ToolStripItem수행합니다.

적용 대상