TextBoxBase.Select(Int32, Int32) 메서드

정의

텍스트 상자의 텍스트 범위를 선택합니다.

public:
 void Select(int start, int length);
public void Select (int start, int length);
override this.Select : int * int -> unit
Public Sub Select (start As Integer, length As Integer)

매개 변수

start
Int32

텍스트 상자에서 현재 선택한 텍스트의 첫 번째 문자에 대한 위치입니다.

length
Int32

선택할 문자의 수입니다.

예외

start 매개 변수 값이 0보다 작은 경우

예제

다음 코드 예제에서는 TextBox파생 클래스인 "fox"라는 단어의 인스턴스에 대한 컨트롤의 내용을 검색합니다. 이 경우 코드는 메서드를 사용하여 Select 컨트롤에서 단어를 선택합니다. 이 예제에서는 이름이 textBox1 만들어졌으며 해당 Text 속성에 "빠른 갈색 여우가 게으른 개 위로 점프합니다"라는 문장이 포함되어 있어야 TextBox 합니다.

public:
   void SelectMyString()
   {
      // Create a string to search for the word "fox".
      String^ searchString = "fox";
      // Determine the starting location of the word "fox".
      int index = textBox1->Text->IndexOf( searchString, 16, 3 );
      // Determine if the word has been found and select it if it was.
      if ( index != -1 )
      {
         // Select the string using the index and the length of the string.
         textBox1->Select( index,searchString->Length );
      }
   }
public void SelectMyString()
 {
    // Create a string to search for the word "fox".
    String searchString = "fox";
    // Determine the starting location of the word "fox".
    int index = textBox1.Text.IndexOf(searchString, 16, 3);
    // Determine if the word has been found and select it if it was.
    if (index != -1)
    {
       // Select the string using the index and the length of the string.
       textBox1.Select(index, searchString.Length);
    }
 }
Public Sub SelectMyString()
    ' Create a string to search for the word "fox".
    Dim searchString As String = "fox"
    ' Determine the starting location of the word "fox".
    Dim index As Integer = textBox1.Text.IndexOf(searchString, 16, 3)
    ' Determine if the word has been found and select it if it was.
    If index <> - 1 Then
        ' Select the string using the index and the length of the string.
        textBox1.Select(index, searchString.Length)
    End If
End Sub

설명

시작 위치를 컨트롤 텍스트의 첫 번째 문자로 설정하려면 매개 변수를 start 0으로 설정합니다. 이 메서드를 사용하여 컨트롤의 텍스트를 검색하고 정보를 바꿀 때와 같이 텍스트의 부분 문자열을 선택할 수 있습니다.

참고

캐럿을 이동할 텍스트 상자 내의 위치로 매개 변수를 설정하고 start 매개 변수를 0 값으로 설정 length 하여 텍스트 상자 내에서 캐럿을 프로그래밍 방식으로 이동할 수 있습니다. 텍스트를 이동하려면 텍스트 상자에 포커스가 있어야 합니다.

참고

매개 변수 없이 이 메서드를 호출하면 대체 메서드가 사용됩니다. 이 대체 메서드는 클래스에서 Control 상속됩니다. 호출되면 입력 포커스를 컨트롤로 설정하고 컨트롤의 내용을 선택합니다. 자세한 내용은 Control.Select 메서드를 참조하세요.

적용 대상

추가 정보