Partager via


TextBoxBase.Select(Int32, Int32) Méthode

Définition

Sélectionne une plage de texte dans la zone de texte.

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)

Paramètres

start
Int32

Position du premier caractère dans la sélection de texte actuelle dans la zone de texte.

length
Int32

Nombre de caractères à sélectionner.

Exceptions

La valeur du start paramètre est inférieure à zéro.

Exemples

L’exemple de code suivant utilise TextBox, une classe dérivée, pour rechercher le contenu du contrôle pour l’instance du mot « fox ». S’il est trouvé, le code sélectionne le mot dans le contrôle à l’aide de la Select méthode. Cet exemple exige qu’un TextBox nom textBox1 ait été créé et que sa Text propriété contient la phrase « Le renard brun rapide saute sur le chien paresseux ».

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

Remarques

Si vous souhaitez définir la position de début sur le premier caractère dans le texte du contrôle, définissez le start paramètre sur 0. Vous pouvez utiliser cette méthode pour sélectionner une sous-chaîne de texte, par exemple lors de la recherche dans le texte du contrôle et le remplacement des informations.

Note

Vous pouvez déplacer par programmation le point d’insertion dans la zone de texte en définissant le start paramètre sur la position dans la zone de texte où vous souhaitez que le point d’insertion se déplace et définisse le length paramètre sur une valeur zéro (0). La zone de texte doit avoir le focus pour que le pointeur soit déplacé.

Note

Si cette méthode est appelée sans paramètres, une autre méthode est utilisée. Cette autre méthode hérite de la Control classe. Lorsqu’elle est appelée, elle définit le focus d’entrée sur le contrôle et sélectionne le contenu du contrôle. Pour plus d’informations, consultez la Control.Select méthode.

S’applique à

Voir aussi