[英]RichTextBox text highlighting
In my form there's a UserControl
that has multiple RichTextBox
's and TexBox
's. 在我的表单中,有一个
UserControl
,它具有多个RichTextBox
和TexBox
。
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. 在通过键盘切换到
TextBox
的同时,只要TextBox
获得焦点,其中的整个文本就会以蓝色背景突出显示。 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. 现在,当通过键盘切换到
RichTextBox
,只要获得RichTextBox
的焦点,光标就会显示在框内,并且没有文本用蓝色背景highlighted
。 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? 当通过键盘选项卡获得焦点时,如何使
RichTextBox
也以蓝色背景突出显示文本?
Just use the Enter
event and call the SelectAll()
method. 只需使用
Enter
事件并调用SelectAll()
方法即可。
private void richTextBox1_Enter(object sender, EventArgs e)
{
richTextBox1.SelectAll();
}
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.