Export (0) Print
Expand All

TextBoxBase.HideSelection Property

Gets or sets a value indicating whether the selected text in the text box control remains highlighted when the control loses focus.

[Visual Basic]
Public Property HideSelection As Boolean
[C#]
public bool HideSelection {get; set;}
[C++]
public: __property bool get_HideSelection();
public: __property void set_HideSelection(bool);
[JScript]
public function get HideSelection() : Boolean;
public function set HideSelection(Boolean);

Property Value

true if the selected text does not appear highlighted when the text box control loses focus; false, if the selected text remains highlighted when the text box control loses focus. The default is true.

Remarks

You can use this property to keep text highlighted in a text box control while another form or a dialog box has focus, such as a spelling checker dialog box.

Example

[Visual Basic, C#] The following code example demonstrates how use the HideSelection property. To run the example, paste the following code in a form containing a TextBox control called TextBox1 and a RichTextBox control called RichTextBox1. This example assumes the event-handling method has been associated with the KeyDown event.

[Visual Basic] 
'Handles the Enter key being pressed while TextBox1 has focus. 
Private Sub TextBox1_KeyDown(ByVal sender As Object, _
    ByVal e As KeyEventArgs) Handles TextBox1.KeyDown
    TextBox1.HideSelection = False
    If e.KeyCode = Keys.Enter Then
        e.Handled = True

        ' Copy the text from TextBox1 to RichTextBox1, add a CRLF after 
        ' the copied text, and keep the caret in view.
        RichTextBox1.SelectedText = TextBox1.Text + _
            Microsoft.VisualBasic.vbCrLf
        RichTextBox1.ScrollToCaret()
    End If
End Sub

[C#] 
//Handles the Enter key being pressed while TextBox1 has focus. 
private void TextBox1_KeyDown(object sender, KeyEventArgs e)
{
    TextBox1.HideSelection = false;
    if (e.KeyCode==Keys.Enter)
    {
        e.Handled = true;

        // Copy the text from TextBox1 to RichTextBox1, add a CRLF after 
        // the copied text, and keep the caret in view.
        RichTextBox1.SelectedText = TextBox1.Text + "\r\n";
        RichTextBox1.ScrollToCaret();
    }
}

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

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

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

Show:
© 2014 Microsoft