Uređivanje

Dijeli putem


Control.Tag Property

Definition

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

public:
 property System::Object ^ Tag { System::Object ^ get(); void set(System::Object ^ value); };
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter))]
public object Tag { get; set; }
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter))]
public object? Tag { get; set; }
[<System.ComponentModel.Bindable(true)>]
[<System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter))>]
member this.Tag : obj with get, set
Public Property Tag As Object

Property Value

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

Attributes

Examples

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 = gcnew CustomerForm;
      customerForm->Tag = gcnew Customer;
      customerForm->Show();
   }
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();
   customerForm.Show();
}
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()
   customerForm.Show()
End Sub

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 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.

Applies to

See also