TextBoxBase.Select(Int32, Int32) Metoda

Definicja

Wybiera zakres tekstu w polu tekstowym.

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)

Parametry

start
Int32

Pozycja pierwszego znaku w bieżącym zaznaczeniu tekstu w polu tekstowym.

length
Int32

Liczba znaków do wybrania.

Wyjątki

Wartość parametru start jest mniejsza niż zero.

Przykłady

W poniższym przykładzie kodu użyto TextBoxklasy pochodnej , aby wyszukać zawartość kontrolki dla wystąpienia słowa "fox". W przypadku znalezienia kod wybiera słowo w kontrolce przy użyciu Select metody . Ten przykład wymaga TextBox utworzenia nazwy textBox1 , a jej Text właściwość zawiera zdanie "Szybki brązowy lis skacze nad leniwym psem".

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

Uwagi

Jeśli chcesz ustawić pozycję początkową na pierwszy znak w tekście kontrolki, ustaw start parametr na 0. Za pomocą tej metody można wybrać podciąg tekstu, na przykład podczas wyszukiwania tekstu kontrolki i zastępowania informacji.

Uwaga

Możesz programowo przenieść daszek w polu tekstowym, ustawiając start parametr na pozycję w polu tekstowym, w którym ma zostać przeniesiony daszek i ustawić length parametr na wartość zero (0). Pole tekstowe musi mieć fokus, aby daszek został przeniesiony.

Uwaga

Jeśli ta metoda jest wywoływana bez żadnych parametrów, zostanie użyta alternatywna metoda. Ta alternatywna metoda dziedziczy z Control klasy. Po wywołaniu ustawia fokus wejściowy na kontrolkę i wybiera zawartość kontrolki. Aby uzyskać więcej informacji, zobacz metodę Control.Select .

Dotyczy

Zobacz też