다음을 통해 공유


Control.Tag 속성

컨트롤에 대한 데이터가 들어 있는 개체를 가져오거나 설정합니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<LocalizableAttribute(False)> _
<BindableAttribute(True)> _
Public Property Tag As Object
‘사용 방법
Dim instance As Control
Dim value As Object

value = instance.Tag

instance.Tag = value
[LocalizableAttribute(false)] 
[BindableAttribute(true)] 
public Object Tag { get; set; }
[LocalizableAttribute(false)] 
[BindableAttribute(true)] 
public:
property Object^ Tag {
    Object^ get ();
    void set (Object^ value);
}
/** @property */
public Object get_Tag ()

/** @property */
public void set_Tag (Object value)
public function get Tag () : Object

public function set Tag (value : Object)

속성 값

컨트롤에 대한 데이터가 들어 있는 Object입니다. 기본값은 Null 참조(Visual Basic의 경우 Nothing)입니다.

설명

Object 클래스에서 파생된 형식은 모두 이 속성에 할당될 수 있습니다. Tag 속성이 Windows Forms 디자이너를 통해 설정되는 경우에는 텍스트만 할당할 수 있습니다.

Tag 속성은 대개 컨트롤과 밀접하게 연결된 데이터를 저장하는 데 사용됩니다. 예를 들어, 고객 정보를 표시하는 컨트롤이 있는 경우 데이터에 빠르게 액세스할 수 있도록 해당 컨트롤의 Tag 속성에 고객의 주문 기록이 들어 있는 DataSet을 저장할 수 있습니다.

예제

다음 코드 예제에서는 폼을 표시하고 해당 Tag 속성에 Customer를 저장합니다. 이 예제를 실행하려면 CustomerForm이라는 Form에서 파생된 클래스 및 Customer가 정의되어 있어야 합니다.

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
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:
   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.set_Tag(new Customer());
    customerForm.Show();
} //buttonNewCustomer_Click

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0에서 지원

참고 항목

참조

Control 클래스
Control 멤버
System.Windows.Forms 네임스페이스
Object