共用方式為


Shape.Tag 屬性

取得或設定物件,其包含線條或圖形控制項的資料。

命名空間:  Microsoft.VisualBasic.PowerPacks
組件:  Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

語法

'宣告
<BrowsableAttribute(True)> _
Public Property Tag As Object
[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)

屬性值

類型:Object
Object ,其中包含與控制項相關聯的資料。The default is a null reference (Nothing in Visual Basic).

備註

衍生自任何型別Object類別可以指派給這個屬性。 如果Tag透過 Windows Form 設計工具設定屬性,可以指定只有文字。

常見用法Tag屬性是用來儲存與控制項密切相關的資料。 例如,如果您有代表網路拓撲中的物件圖形控制項,您可能會儲存DataSet,其中包含在該物件的相關資訊Tag屬性,以便快速存取資料。

範例

下列範例示範如何使用Tag屬性來傳遞的執行個體NodeInfo新表單的類別。 此範例中您需要RectangleShape控制項在表單中,具有名為 networkForm,第二個表單,而且您已定義名為 RectangleShape1NodeInfo專案中的類別。

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 安全性

請參閱

參考

Shape 類別

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

如何:使用 LineShape 控制項繪製線條 (Visual Studio)

如何:使用 OvalShape 和 RectangleShape 控制項繪製圖案 (Visual Studio)

Line 和 Shape 控制項簡介 (Visual Studio)