读书人

一个关于RichTextBox的有关问题可能

发布时间: 2013-11-02 19:41:10 作者: rapoo

一个关于RichTextBox的问题,可能很简单,但是我搞不懂~



这段代码,为什么字母b的样式会跟字母a一样的?
就算我继续搞n个字母,那么前n-1个字母的样式都会跟第一个的一样,只有最后一个字母的样式跟想要的样式设定成一样的。实在不解,估计是用错Select方法了……

这样是没问题了:


可是,我的文本在程序运行过程中要不断被更新啊,那该怎么办好呢? RichTextBox? 文本?
[解决办法]
哪你就可以等文本更新好了在重新执行颜色设置代码块,是否可以解决你的问题。
[解决办法]
试试看加上一个

this.rtbScreen.Text += "a";
Application.DoEvents();
this.rtbScreen.Select(0, 1);
this.rtbScreen.SelectionBackColor = Color.Red;
this.rtbScreen.SelectionColor = Color.Cyan;

this.rtbScreen.Text += "b";
Application.DoEvents();
this.rtbScreen.Select(1, 1);
this.rtbScreen.SelectionBackColor = Color.Green;
this.rtbScreen.SelectionColor = Color.Yellow;

this.rtbScreen.Text += "c";
Application.DoEvents();
this.rtbScreen.Select(2, 1);


this.rtbScreen.SelectionBackColor = Color.Blue;
this.rtbScreen.SelectionColor = Color.White;

再不行试试SelectionStart和SelectionLength
[解决办法]

 

读书人网 >C#

热点推荐