在RichTextBox中突出显示整行 [英] Highlight the entire line in a RichTextBox

查看:95
本文介绍了在RichTextBox中突出显示整行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要突出显示整个行,从头到尾都无所谓,字符是否存在以及行可能为空,但它应该突出显示整个行。

I want to highlight the entire line, from start to end doesn't matter whether characters are present or not and line may be blank but it should highlight the complete line.



Like

推荐答案

如果 WordWrap 已关闭,请在 RichTextBox 中突出显示一行:

This will highlight a full line in a RichTextBox if WordWrap is off:

void highLightALine(RichTextBox rtb, int line, Color hiLight)
{
    int i1 = rtb.GetFirstCharIndexFromLine(line);
    int i2 = rtb.GetFirstCharIndexFromLine(line + 1);
    if (i2 < 0) i2 = rtb.Text.Length;

    rtb.SelectionStart = i1;
    rtb.SelectionLength = i2 - i1;
    rtb.SelectionBackColor = hiLight;
}

请注意,如果 WordWrap 是的,它仍将突出显示该行,但仅在可见范围内。

Note that if WordWrap is true it will still highlight the line but only as far as it is visible. Its continuation on the next line will not be changed.

还要注意,只有 Text 可以突出显示。 空的空间无法突出显示此处是尝试所有者绘制RTB子类的示例。

Also note that only Text can be highlighted. Empty space can't be highlighted afaik. Here is an example of trying to owner-draw an RTB subclass..

这篇关于在RichTextBox中突出显示整行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆