Reputation: 203
In my form there's a UserControl
that has multiple RichTextBox
's and TexBox
's.
While tabbing into TextBox
's via keyboard, as soon as a TextBox
get focus the entire text in it is highlighted in a blue background. Looks like a default behavior.
Now while tabbing into RichTextBox
's via keyboard, as soon as a RichTextBox
get's focus, the cursor is shown inside the box and no text is highlighted
with blue background. Probably a default behavior.
How can i make the RichTextBox
also to highlight the text in blue background whenit get's focus via keyboard tabbing?
Upvotes: 1
Views: 101
Reputation: 678
If you are looking to change the background color rather than select the text you can use something like the following.
private void richTextBox1_Enter(object sender, EventArgs e)
{
richTextBox1.BackColor = Color.LightBlue;
}
private void richTextBox1_Leave(object sender, EventArgs e)
{
richTextBox1.BackColor = Color.White;
}
Upvotes: 1
Reputation: 13816
Just use the Enter
event and call the SelectAll()
method.
private void richTextBox1_Enter(object sender, EventArgs e)
{
richTextBox1.SelectAll();
}
Upvotes: 5