共用方式為


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)

Syntax

'宣告
<BrowsableAttribute(True)> _
Public Property Tag As Object
    Get
    Set
[BrowsableAttribute(true)]
public Object Tag { get; set; }
[BrowsableAttribute(true)]
public:
property Object^ Tag {
    Object^ get ();
    void set (Object^ value);
}
[<BrowsableAttribute(true)>]
member Tag : Object with get, set
function get Tag () : Object
function set Tag (value : Object)

Property Value

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

Remarks

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.

Examples

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 Sub Form1_Load() Handles MyBase.Load
    ' Declare an instance of a NodeInfo class.
    Dim MyNode As New NodeInfo
    ' Assign the instance to the Tag property.
    RectangleShape1.Tag = MyNode
End Sub

Private Sub RectangleShape1_Click() Handles RectangleShape1.Click
    ' Declare an instance of a networkForm form.
    Dim networkForm As 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()
End Sub
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();
}

.NET Framework Security

See Also

Reference

Shape Class

Microsoft.VisualBasic.PowerPacks Namespace

Other Resources

How to: Draw Lines with the LineShape Control (Visual Studio)

How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)

Introduction to the Line and Shape Controls (Visual Studio)