This documentation is archived and is not being maintained.

Control.Tag Property

Gets or sets the object that contains data about the control.

[Visual Basic]
Public Property Tag As Object
public object Tag {get; set;}
public: __property Object* get_Tag();
public: __property void set_Tag(Object*);
public function get Tag() : Object;
public function set Tag(Object);

Property Value

An Object that contains data about 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 control that displays information about a customer you, might store a DataSet that contains the customer's order history in that control's Tag property so the data can be accessed quickly.


[Visual Basic, C#, C++] The following example displays a form and stores a Customer object in its Tag property. This example assumes you have defined a class that derives from Form named CustomerForm and that you have defined a Customer object.

[Visual Basic] 
Private Sub buttonNewCustomer_Click(sender As Object, _
  e As EventArgs) Handles buttonNewCustomer.Click
   ' Create a new customer form and assign a new 
   ' Customer object to the Tag property. 
   Dim customerForm As New CustomerForm()
   customerForm.Tag = New Customer()
End Sub

private void buttonNewCustomer_Click(object sender, EventArgs e)
   /* Create a new customer form and assign a new 
    * Customer object to the Tag property. */
   CustomerForm customerForm = new CustomerForm();
   customerForm.Tag = new Customer();

    void buttonNewCustomer_Click(Object* /*sender*/, EventArgs* /*e*/) {
        /* Create a new customer form and assign a new
        * Customer object to the Tag property. */
        CustomerForm* customerForm = new CustomerForm();
        customerForm->Tag = new Customer();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Windows.Forms Namespace | Object