Udostępnij za pośrednictwem


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 przeszukać zawartość kontrolki dla wystąpienia słowa "fox". W przypadku znalezienia kod wybiera słowo w kontrolce Select przy użyciu metody . Ten przykład wymaga, aby TextBox nazwa textBox1 została utworzona, 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 / Notatka

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

Uwaga / Notatka

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

Dotyczy

Zobacz też