다음을 통해 공유


Label 클래스

표준 Windows 레이블을 나타냅니다.

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

구문

‘선언
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class Label
    Inherits Control
‘사용 방법
Dim instance As Label
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class Label : Control
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
[ComVisibleAttribute(true)] 
public ref class Label : public Control
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class Label extends Control
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class Label extends Control

설명

Label 컨트롤은 일반적으로 컨트롤에 설명문을 제공하는 데 사용됩니다. 예를 들어, Label을 사용하여 TextBox 컨트롤에 설명문을 추가하면 사용자에게 컨트롤에서 예상되는 데이터 형식을 알려줄 수 있습니다. 또한 Label 컨트롤을 사용하여 Form에 설명문을 추가하면 사용자에게 유용한 정보를 제공할 수 있습니다. 예를 들어, Form의 맨 위에 Label을 추가하여 사용자에게 이 폼의 컨트롤에 데이터를 입력하는 방법을 보여 줄 수 있습니다. 또한 Label 컨트롤을 사용하여 응용 프로그램의 상태에 대한 런타임 정보를 표시할 수도 있습니다. 예를 들어, 폼에 Label 컨트롤을 추가하여 파일 목록이 처리될 때 각 파일의 상태를 표시할 수 있습니다.

Label은 폼의 탭 순서를 따르지만 포커스를 받지는 않습니다. 탭 순서의 다음 컨트롤이 포커스를 받습니다. 예를 들어, UseMnemonic 속성을 true로 설정하고 컨트롤의 Text 속성에 니모닉 문자(앰퍼샌드(&) 다음에 오는 첫 번째 문자)를 지정한 경우 사용자가 Alt 키와 해당 니모닉 키를 동시에 누르면 포커스가 탭 순서의 다음 컨트롤로 이동합니다. 이 기능은 폼에 키보드 탐색 기능을 제공합니다. Label 컨트롤은 텍스트를 표시할 뿐 아니라 Image 속성 또는 ImageIndexImageList 속성을 조합하여 이미지를 표시할 수도 있습니다.

참고

BackColor 속성을 Color.Transparent로 설정하여 Label을 투명하게 만들 수 있습니다. 투명한 레이블을 사용할 경우 현재 장치 좌표계만 사용하여 컨테이너에 그려야 합니다. 그렇지 않으면 Label 배경이 잘못 칠해질 수도 있습니다.

예제

다음 코드 예제에서는 3차원 테두리와 이미지가 포함되어 있는 Label 컨트롤을 만드는 방법을 보여 줍니다. 이미지는 ImageListImageIndex 속성을 사용하여 표시됩니다. 또한 이 컨트롤에는 지정된 니모닉 문자를 사용하는 캡션이 있습니다. 이 예제 코드에서는 PreferredHeightPreferredWidth 속성을 사용하여 Label 컨트롤의 크기를 적절하게 조정합니다. 이 예제를 실행하려면 imageList1이라는 이름으로 ImageList가 만들어져 있고 여기에 두 개의 이미지가 로드되어 있어야 합니다. 또한 이 예제를 실행하려면 해당 코드에 System.Drawing 네임스페이스가 추가된 폼 안에 코드가 있어야 합니다.

Public Sub CreateMyLabel()
    ' Create an instance of a Label.
    Dim label1 As New Label()
       
    ' Set the border to a three-dimensional border.
    label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    ' Set the ImageList to use for displaying an image.
    label1.ImageList = imageList1
    ' Use the second image in imageList1.
    label1.ImageIndex = 1
    ' Align the image to the top left corner.
    label1.ImageAlign = ContentAlignment.TopLeft
     
    ' Specify that the text can display mnemonic characters.
    label1.UseMnemonic = True
    ' Set the text of the control and specify a mnemonic character.
    label1.Text = "First &Name:"
       
    ' Set the size of the control based on the PreferredHeight and PreferredWidth values. 
    label1.Size = New Size(label1.PreferredWidth, label1.PreferredHeight)

    '...Code to add the control to the form...
End Sub
public void CreateMyLabel()
{
   // Create an instance of a Label.
   Label label1 = new Label();

   // Set the border to a three-dimensional border.
   label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
   // Set the ImageList to use for displaying an image.
   label1.ImageList = imageList1;
   // Use the second image in imageList1.
   label1.ImageIndex = 1;
   // Align the image to the top left corner.
   label1.ImageAlign = ContentAlignment.TopLeft;

   // Specify that the text can display mnemonic characters.
   label1.UseMnemonic = true;
   // Set the text of the control and specify a mnemonic character.
   label1.Text = "First &Name:";
   
   /* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
   label1.Size = new Size (label1.PreferredWidth, label1.PreferredHeight);

   //...Code to add the control to the form...
}
public:
   void CreateMyLabel()
   {
      // Create an instance of a Label.
      Label^ label1 = gcnew Label;
      
      // Set the border to a three-dimensional border.
      label1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
      // Set the ImageList to use for displaying an image.
      label1->ImageList = imageList1;
      // Use the second image in imageList1.
      label1->ImageIndex = 1;
      // Align the image to the top left corner.
      label1->ImageAlign = ContentAlignment::TopLeft;
      
      // Specify that the text can display mnemonic characters.
      label1->UseMnemonic = true;
      // Set the text of the control and specify a mnemonic character.
      label1->Text = "First &Name:";
      
      /* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
      label1->Size = System::Drawing::Size( label1->PreferredWidth, label1->PreferredHeight );
      
      //...Code to add the control to the form...
   }
public void CreateMyLabel()
{
    // Create an instance of a Label.
    Label label1 = new Label();
    // Set the border to a three-dimensional border.
    label1.set_BorderStyle(System.Windows.Forms.BorderStyle.Fixed3D);
    // Set the ImageList to use for displaying an image.
    label1.set_ImageList(imageList1);
    // Use the second image in imageList1.
    label1.set_ImageIndex(1);
    // Align the image to the top left corner.
    label1.set_ImageAlign(ContentAlignment.TopLeft);
    // Specify that the text can display mnemonic characters.
    label1.set_UseMnemonic(true);
    // Set the text of the control and specify a mnemonic character.
    label1.set_Text("First &Name:");
    /* Set the size of the control based on the PreferredHeight
       and PreferredWidth values. */
    label1.set_Size(new Size(label1.get_PreferredWidth(), 
        label1.get_PreferredHeight()));
    //...Code to add the control to the form...
} //CreateMyLabel 
public function CreateMyLabel()
{
   // Create an instance of a Label.
   var label1 : Label = new Label();

   // Set the border to a three-dimensional border.
   label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
   // Set the ImageList to use for displaying an image.
   label1.ImageList = imageList1;
   // Use the second image in imageList1.
   label1.ImageIndex = 1;
   // Align the image to the top left corner.
   label1.ImageAlign = ContentAlignment.TopLeft;

   // Specify that the text can display mnemonic characters.
   label1.UseMnemonic = true;
   // Set the text of the control and specify a mnemonic character.
   label1.Text = "First &Name:";
   
   /* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
   label1.Size = new System.Drawing.Size (label1.PreferredWidth, label1.PreferredHeight);

   //...Code to add the control to the form...
}

상속 계층 구조

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
        System.Windows.Forms.Label
           System.Windows.Forms.LinkLabel

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

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, 1.0에서 지원

참고 항목

참조

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