Sdílet prostřednictvím


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á TextBox, odvozené třídy, hledat obsah ovládacího prvku instance slova "fox". Pokud se najde, kód pomocí metody vybere slovo v ovládacím Select prvku. Tento příklad vyžaduje, aby TextBox byl pojmenovaný textBox1 vytvořen a jeho Text vlastnost obsahuje větu "Rychlá hnědá liška přeskakuje přes opožděného psa".

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). Textové pole musí mít fokus, aby se stříška přesunula.

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 metodě Control.Select.

Platí pro

Viz také