RichTextBox的颜色选择线 [英] RichTextBox color selected lines

查看:100
本文介绍了RichTextBox的颜色选择线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的窗口形式。我使用VS 2008,C#写一个RichTextBox。
我希望能够以色每一行用不同的颜色,因为我写的RichTextBox。有人能指出我来样订做。
谢谢



 的foreach(在myfiles的字符串文件)
{
//当我处理我的文件
// richTextBox1.Text + =我的处理结果;
如果(文件==somefileName)
{
//颜色上面输入线或输入新的彩色线条
}

}


解决方案

设置 selectionColor设置你追加之前,是这样的:

  INT行= 0; 
的foreach(在myfiles的字符串文件)
{
//无论采用哪种方式,你要选择一种颜色,这里
//我只是与红色和蓝色$ B $交替b richTextBox1.SelectionColor =
线%2 == 0? Color.Red:Color.Blue;

// AppendText通过比rtb.Text + = ...
richTextBox1.AppendText(文件+\r\\\
)为佳;
线++;
}


I am new to windows Forms. I am using VS 2008, C# to write a RichTextBox. I want to be able to color each line with a different color as I write to the RichTextBox. Can someone point me to samples. Thanks

foreach (string file in myfiles)
{
  // As I process my files
  // richTextBox1.Text += "My processing results";
  if(file == "somefileName")
  {
    // Color above entered line or enter new colored line
  }

}

解决方案

Set SelectionColor before you append, something like:

    int line = 0;
    foreach (string file in myfiles)
    {
        // Whatever method you want to choose a color, here
        // I'm just alternating between red and blue
        richTextBox1.SelectionColor = 
            line % 2 == 0 ? Color.Red : Color.Blue;

        // AppendText is better than rtb.Text += ...
        richTextBox1.AppendText(file + "\r\n");
        line++;
    }

这篇关于RichTextBox的颜色选择线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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