Tag Property
Collapse the table of content
Expand the table of content

Control.Tag Property


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

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public object Tag { get; set; }

Property Value

Type: System.Object

An Object that contains data about the control. The default is null.

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.

The following code example displays a form and stores a Customer in its Tag property. This example requires that you have defined a class that derives from Form named CustomerForm and that you have defined a Customer.

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();

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft