日期:2014-05-17  浏览次数:20677 次

一个关于RichTextBox的问题,可能很简单,但是我搞不懂~
            this.rtbScreen.Text += "a";
            this.rtbScreen.Select(0, 1);
            this.rtbScreen.SelectionBackColor = Color.Red;
            this.rtbScreen.SelectionColor = Color.Cyan;            

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

            this.rtbScreen.Text += "c";
            this.rtbScreen.Select(2, 1);
            this.rtbScreen.SelectionBackColor = Color.Blue;
            this.rtbScreen.SelectionColor = Color.White;




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

这样是没问题了:
            this.rtbScreen.Text += "abc";
            this.rtbScreen.Select(0, 1);
            this.rtbScreen.SelectionBackColor = Color.Red;
            this.rtbScreen.SelectionColor = Color.Cyan;            

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

            //this.rtbScreen.Text += "c";
            this.rtbScreen.Select(2, 1);
            this.rtbScreen.SelectionBackColor = Color.Blue;
            this.rtbScreen.SelectionColor = Color.White;




可是,我的文本在程序运行过程中要不断被更新啊,那该怎么办好呢?
RichTextBox? 文本?