Export (0) Print
Expand All

Shape.Tag Property

Gets or sets the object that contains data about a line or shape control.

Namespace:  Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

[BrowsableAttribute(true)]
public Object Tag { get; set; }

Property Value

Type: System.Object
An Object that contains data associated with the control. The default is a null reference (Nothing in Visual Basic).

Any type derived from the Object class can be assigned to this property. If the Tag property is set through the Windows Forms Designer, only text can be assigned.

A common use for the Tag property is to store data that is closely associated with the control. For example, if you have a shape control that represents an object in a network topography, you might store a DataSet that contains information about that object in the Tag property so the data can be accessed quickly.

The following example demonstrates how to use the Tag property to pass an instance of a NodeInfo class to a new form. This example requires that you have a RectangleShape control named RectangleShape1 on a form, that you have a second form named networkForm, and that you have defined a NodeInfo class in your project.

private void Form1_Load(System.Object sender, System.EventArgs e)
{
    // Declare an instance of a NodeInfo class.
    NodeInfo MyNode = new NodeInfo();
    // Assign the instance to the Tag property.
    rectangleShape1.Tag = MyNode;
}

private void rectangleShape1_Click(System.Object sender, System.EventArgs e)
{
    // Declare an instance of a networkForm form.
    Form networkForm = new Form();
    // Assign the Tag property of the RectangleShape to the new form. 
    // This passes the MyNode instance of the NodeInfo class to the 
    // form.
    networkForm.Tag = rectangleShape1.Tag;
    // Show the new form.
    networkForm.Show();
}

Show:
© 2014 Microsoft