TextBoxBase.Select(Int32, Int32) Metoda

Definice

Vybere oblast textu v textovém poli.

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

Pozice prvního znaku v aktuálním výběru textu v textovém poli.

length
Int32

Počet znaků, které chcete vybrat.

Výjimky

Hodnota parametru start je menší než nula.

Příklady

Následující příklad kódu používá TextBoxk vyhledávání obsahu ovládacího prvku instanci slova "fox". Pokud se najde, kód vybere slovo v ovládacím prvku pomocí Select metody. Tento příklad vyžaduje, aby pojmenovaný TextBox textBox1 byl vytvořen a jeho Text vlastnost obsahuje větu "Rychlá hnědá liška přeskakuje přes opožděný pes".

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

Poznámky

Pokud chcete nastavit počáteční pozici na první znak v textu ovládacího prvku, nastavte start parametr na hodnotu 0. Tuto metodu můžete použít k výběru podřetězí textu, například při hledání textu ovládacího prvku a nahrazení informací.

Poznámka

Kurzor v textovém poli můžete programově přesunout nastavením start parametru na pozici v textovém poli, do kterého se má kurzor přesunout, a nastavit length parametr na hodnotu nuly (0). Aby bylo možné přesunout stříšku, musí mít textové pole fokus.

Poznámka

Pokud se tato metoda volá bez parametrů, použije se alternativní metoda. Tato alternativní metoda dědí z Control třídy. Při zavolání nastaví vstupní fokus na ovládací prvek a vybere obsah ovládacího prvku. Další informace najdete v Control.Select metodě.

Platí pro

Viz také