ToolStripItem.Owner Propiedad

Definición

Obtiene o establece el propietario de este elemento.

C#
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.ToolStrip Owner { get; set; }

Valor de propiedad

ToolStrip

ToolStrip que posee o va a poseer el ToolStripItem.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la Owner propiedad para la representación personalizada. Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la ToolStripItem clase .

C#
// This method defines the painting behavior of the control.
// It performs the following operations:
//
// Computes the layout of the item's image and text.
// Draws the item's background image.
// Draws the item's image.
// Draws the item's text.
//
// Drawing operations are implemented in the 
// RolloverItemRenderer class.
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    if (this.Owner != null)
    {
        // Find the dimensions of the image and the text 
        // areas of the item. 
        this.ComputeImageAndTextLayout();

        // Draw the background. This includes drawing a highlighted 
        // border when the mouse is in the client area.
        ToolStripItemRenderEventArgs ea = new ToolStripItemRenderEventArgs(
             e.Graphics,
             this);
        this.Owner.Renderer.DrawItemBackground(ea);

        // Draw the item's image. 
        ToolStripItemImageRenderEventArgs irea =
            new ToolStripItemImageRenderEventArgs(
            e.Graphics,
            this,
            imageRect );
        this.Owner.Renderer.DrawItemImage(irea);

        // If the item is on a drop-down, give its
        // text a different highlighted color.
        Color highlightColor = 
            this.IsOnDropDown ?
            Color.Salmon : SystemColors.ControlLightLight;

        // Draw the text, and highlight it if the 
        // the rollover state is true.
        ToolStripItemTextRenderEventArgs rea =
            new ToolStripItemTextRenderEventArgs(
            e.Graphics,
            this,
            base.Text,
            textRect,
            this.rolloverValue ? highlightColor : base.ForeColor,
            base.Font,
            base.TextAlign);
        this.Owner.Renderer.DrawItemText(rea);
    }
}

Comentarios

Owner devuelve la ToolStrip colección Items cuya colección Items contiene el objeto actual ToolStripItem. Esta es la mejor manera de hacer referencia ImageList a u otras propiedades en el nivel ToolStrip superior sin escribir código especial para controlar el desbordamiento.

Owner sigue siendo el mismo aunque el elemento se encuentre en .ToolStripOverflow Owner puede ser null para determinados elementos que se encuentran en la DisplayedItems colección, pero no en la Items colección.

Se aplica a

Producto Versiones
.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