다음을 통해 공유


TextBox 클래스

Windows TextBox 컨트롤을 나타냅니다.

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

구문

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

설명

TextBox 컨트롤을 사용하면 사용자가 응용 프로그램에 텍스트를 입력할 수 있습니다. 이 컨트롤에는 여러 줄 편집 및 암호 문자 마스킹을 비롯하여 표준 Windows TextBox 컨트롤에는 없던 추가 기능이 있습니다.

일반적으로 TextBox 컨트롤은 텍스트를 한 줄로 입력하고 표시하는 데 사용됩니다. MultilineScrollBars 속성을 사용하면 여러 줄의 텍스트를 표시하거나 입력할 수 있습니다. AcceptsTabAcceptsReturn 속성을 true로 설정하면 여러 줄을 입력할 수 있는 TextBox 컨트롤에서 더 많은 텍스트 조작이 가능합니다.

MaxLength 속성을 특정 문자 수로 설정하면 TextBox에 입력되는 텍스트의 길이를 제한할 수 있습니다. 또한 TextBox 컨트롤은 암호 및 기타 중요한 정보를 입력하는 데도 사용할 수 있습니다. PasswordChar 속성을 사용하면 한 줄만 입력할 수 있는 컨트롤의 문자를 마스킹할 수 있습니다. CharacterCasing 속성을 사용하면 사용자가 TextBox 컨트롤에 대문자, 소문자 또는 대문자와 소문자의 조합을 입력할 수 있도록 지정할 수 있습니다.

TextBox 컨트롤에 입력되는 텍스트를 제한하려면, 컨트롤에 입력하는 각 문자의 유효성을 검사할 수 있도록 KeyDown 이벤트에 대한 이벤트 처리기를 만듭니다. 또한 ReadOnly 속성을 true로 설정하여 TextBox 컨트롤에 있는 데이터의 모든 엔트리를 제한할 수도 있습니다.

참고

TextBox 컨트롤의 대부분의 기능은 TextBoxBase 클래스에서 상속됩니다.

참고

TextBox 컨트롤에 비주얼 스타일을 사용하면 서로게이트 글꼴이 올바르지 않게 처리됩니다.

Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE 플랫폼 참고: Pocket PC 응용 프로그램의 경우 한 줄만 입력할 수 있는 텍스트 상자에는 탭이 꺾쇠괄호로 표시되지만 Multilinetrue로 설정하면 탭이 일반적인 방식으로 표시됩니다.

예제

다음 코드 예제에서는 세로 스크롤 막대가 있고 여러 줄을 입력할 수 있는 TextBox 컨트롤을 만듭니다. 이 예제에서는 AcceptsTab, AcceptsReturnWordWrap 속성을 사용하여 여러 줄을 입력할 수 있는 TextBox 컨트롤을 통해 텍스트 문서를 효과적으로 작성할 수 있습니다.

Private Sub CreateMyMultilineTextBox()
    ' Create an instance of a TextBox control.
    Dim textBox1 As New TextBox()
    
    ' Set the Multiline property to true.
    textBox1.Multiline = True
    ' Add vertical scroll bars to the TextBox control.
    textBox1.ScrollBars = ScrollBars.Vertical
    ' Allow the RETURN key to be entered in the TextBox control.
    textBox1.AcceptsReturn = True
    ' Allow the TAB key to be entered in the TextBox control.
    textBox1.AcceptsTab = True
    ' Set WordWrap to True to allow text to wrap to the next line.
    textBox1.WordWrap = True
    ' Set the default text of the control.
    textBox1.Text = "Welcome!"
End Sub
private void CreateMyMultilineTextBox()
 {
    // Create an instance of a TextBox control.
    TextBox textBox1 = new TextBox();
    
    // Set the Multiline property to true.
    textBox1.Multiline = true;
    // Add vertical scroll bars to the TextBox control.
    textBox1.ScrollBars = ScrollBars.Vertical;
    // Allow the RETURN key to be entered in the TextBox control.
    textBox1.AcceptsReturn = true;
    // Allow the TAB key to be entered in the TextBox control.
    textBox1.AcceptsTab = true;
    // Set WordWrap to True to allow text to wrap to the next line.
    textBox1.WordWrap = true;
    // Set the default text of the control.
    textBox1.Text = "Welcome!";
 }
 
private:
   void CreateMyMultilineTextBox()
   {
      // Create an instance of a TextBox control
      TextBox^ textBox1 = gcnew TextBox;
      
      // Set the Multiline property to true.
      textBox1->Multiline = true;
      // Add vertical scroll bars to the TextBox control.
      textBox1->ScrollBars = ScrollBars::Vertical;
      // Allow the RETURN key to be entered in the TextBox control.
      textBox1->AcceptsReturn = true;
      // Allow the TAB key to be entered in the TextBox control.
      textBox1->AcceptsTab = true;
      // Set WordWrap to True to allow text to wrap to the next line.
      textBox1->WordWrap = true;
      // Set the default text of the control.
      textBox1->Text = "Welcome!";
   }
private void CreateMyMultilineTextBox()
{
    // Create an instance of a TextBox control.
    TextBox textBox1 = new TextBox();
    // Set the Multiline property to true.
    textBox1.set_Multiline(true);
    // Add vertical scroll bars to the TextBox control.
    textBox1.set_ScrollBars(ScrollBars.Vertical);
    // Allow the RETURN key to be entered in the TextBox control.
    textBox1.set_AcceptsReturn(true);
    // Allow the TAB key to be entered in the TextBox control.
    textBox1.set_AcceptsTab(true);
    // Set WordWrap to True to allow text to wrap to the next line.
    textBox1.set_WordWrap(true);
    // Set the default text of the control.
    textBox1.set_Text("Welcome!");
} //CreateMyMultilineTextBox
private function CreateMyMultilineTextBox()
 {
    // Create an instance of a TextBox control
    textBox1 = new TextBox();
    
    // Set the Multiline property to true.
    textBox1.Multiline = true;
    // Add vertical scroll bars to the TextBox control.
    textBox1.ScrollBars = ScrollBars.Vertical;
    // Allow the RETURN key to be entered in the TextBox control.
    textBox1.AcceptsReturn = true;
    // Allow the TAB key to be entered in the TextBox control.
    textBox1.AcceptsTab = true;
    // Set WordWrap to True to allow text to wrap to the next line.
    textBox1.WordWrap = true;
    // Set the default text of the control.
    textBox1.Text = "Welcome!";
 }
 

상속 계층 구조

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.TextBoxBase
          System.Windows.Forms.TextBox
             System.Windows.Forms.DataGridTextBox
             System.Windows.Forms.DataGridViewTextBoxEditingControl

스레드로부터의 안전성

이 형식의 모든 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에서 지원

참고 항목

참조

TextBox 멤버
System.Windows.Forms 네임스페이스
TextBoxBase