This documentation is archived and is not being maintained.

TextBoxBase.Select Method

Selects text within the control.

Overload List

Selects a range of text in the text box.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub Select(Integer, Integer)
[C#] public void Select(int, int);
[C++] public: void Select(int, int);
[JScript] public function Select(int, int);

Inherited from Control.

[Visual Basic] Overloads Public Sub Select()
[C#] public void Select();
[C++] public: void Select();
[JScript] public function Select();

Inherited from Control.

[Visual Basic] Overloads Protected Overridable Sub Select(Boolean, Boolean)
[C#] protected virtual void Select(bool, bool);
[C++] protected: virtual void Select(bool, bool);
[JScript] protected function Select(Boolean, Boolean);

Example

[Visual Basic, C#, C++] The following example uses TextBox, a derived class, to search the contents of the control for the instance of the word "fox". If found, the code selects the word in the control using the Select method. This example assumes that a TextBox named textBox1 has been created and its Text property contains the sentence "The quick brown fox jumps over the lazy dog.".

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Select. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
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, 0, 0)
    ' 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


[C#] 
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, 0, 0);
    // 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);
    }
 }
 

[C++] 
public:
void SelectMyString()
 {
    // Create a string to search for the word "fox".
    String* searchString = S"fox";
    // Determine the starting location of the word "fox".
    int index = textBox1->Text->IndexOf(searchString, 0, 0);
    // 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);
    }
 }
 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

TextBoxBase Class | TextBoxBase Members | System.Windows.Forms Namespace

Show: