ToolStripItem.Owner (Propiedad)
Obtiene o establece el propietario de este elemento.

Espacio de nombres: System.Windows.Forms
Ensamblado: System.Windows.Forms (en system.windows.forms.dll)

Sintaxis

Visual Basic (Declaración)
Public Property Owner As ToolStrip
Visual Basic (Uso)
Dim instance As ToolStripItem
Dim value As ToolStrip

value = instance.Owner

instance.Owner = value
C#
public ToolStrip Owner { get; set; }
C++
public:
property ToolStrip^ Owner {
    ToolStrip^ get ();
    void set (ToolStrip^ value);
}
J#
/** @property */
public ToolStrip get_Owner ()

/** @property */
public void set_Owner (ToolStrip value)
JScript
public function get Owner () : ToolStrip

public function set Owner (value : ToolStrip)
XAML
No aplicable.

Valor de propiedad

ToolStrip que posee o va a poseer el ToolStripItem.
Comentarios

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

Owner sigue siendo igual, incluso aunque el elemento quede dentro de ToolStripOverflow. Owner puede ser referencia null (Nothing en Visual Basic) para ciertos elementos que están en la colección DisplayedItems pero no en la colección Items.

Ejemplo

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

Visual Basic
' 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 Overrides Sub OnPaint(e As PaintEventArgs)
   MyBase.OnPaint(e)
   
   If (Me.Owner IsNot Nothing) Then
      ' Find the dimensions of the image and the text 
      ' areas of the item. 
      Me.ComputeImageAndTextLayout()
      
      ' Draw the background. This includes drawing a highlighted 
      ' border when the mouse is in the client area.
      Dim ea As New ToolStripItemRenderEventArgs(e.Graphics, Me)
      Me.Owner.Renderer.DrawItemBackground(ea)
      
      ' Draw the item's image. 
      Dim irea As New ToolStripItemImageRenderEventArgs(e.Graphics, Me, imageRect)
      Me.Owner.Renderer.DrawItemImage(irea)
      
      ' If the item is on a drop-down, give its
      ' text a different highlighted color.
      Dim highlightColor As Color = IIf(Me.IsOnDropDown, Color.Salmon, SystemColors.ControlLightLight)
      
      ' Draw the text, and highlight it if the 
      ' the rollover state is true.
      Dim rea As New ToolStripItemTextRenderEventArgs(e.Graphics, Me, MyBase.Text, textRect, IIf(Me.rolloverValue, highlightColor, MyBase.ForeColor), MyBase.Font, MyBase.TextAlign)
      Me.Owner.Renderer.DrawItemText(rea)
   End If
 End Sub
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);
    }
}
Plataformas

Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter

Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

Información de versión

.NET Framework

Compatible con: 3.0, 2.0
Vea también

Page view tracker