ToolStripItem.ContentRectangle Özellik

Tanım

Metin ve simgeler gibi içeriğin arka plan kenarlıklarının üzerine yazmadan içine ToolStripItem yerleştirilebileceği alanı alır.

C#
[System.ComponentModel.Browsable(false)]
public System.Drawing.Rectangle ContentRectangle { get; }

Özellik Değeri

Rectangle

Rectangle İçeriğin konumunu ve boyutunu temsil eden dört tamsayı içeren, kenarlığı ToolStripItem hariç.

Öznitelikler

Örnekler

Aşağıdaki kod örneği, özel işleme için özelliğinin ContentRectangle nasıl kullanılacağını gösterir. Bu kod örneği, sınıfı için ToolStripItem sağlanan daha büyük bir örneğin parçasıdır.

C#
// 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);
    }
}

Açıklamalar

ContentRectangle özelliğini kullanarak özel bir ToolStripItemboyama yapın.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7