打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
c#中richtextbox显示不同的颜色

List strWarn=new List();//定义一个泛型,可以自由的添加字段

private void WarnInfo(string str)
       {
           strWarn.Add(str);
           for (int i = 0; i < strWarn.Count; i++)
           {
               int lenth = richTextBox1.Text.Length;
               richTextBox1.AppendText(strWarn[i]);
               if (richTextBox1.Lines[i].Contains("一级警告"))
               {
                   for (int j = 0; strWarn[i][j] != '\n'; j++)//对于这一行来说\n是结尾
                   {
                       richTextBox1.Select(lenth + j, 1);//一个一个的选择然后改变颜色
                       richTextBox1.SelectionColor = Color.Red;
                   }
               }
               if (richTextBox1.Lines[i].Contains("二级警告"))
               {
                   for (int j = 0; strWarn[i][j] != '\n'; j++)
                   {
                       richTextBox1.Select(lenth + j, 1);
                       richTextBox1.SelectionColor = Color.Orange;
                   }
               }
          }
       }

当需要滚动显示出来的信息都是显示最后的信息可以附加:

private void richTextBox1_TextChanged(object sender, EventArgse)
       {
           richTextBox1.SelectionStart = richTextBox1.TextLength;
           // Scrolls the contents of the control to the current caretposition.
           richTextBox1.ScrollToCaret();

       }

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
RichtextBox - VBGood论坛交流
设置RichTextbox行间距
C语言如何从指定行读取文件
NTFS文件系统数据恢复----解析MFT表
排序算法总结 | 菜鸟教程
[数字信号处理]IIR滤波器的直接设计(C代码)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服