c# – RichTextBox颜色选择行
发布时间:2020-12-15 06:51:08 所属栏目:百科 来源:网络整理
导读:我是 Windows窗体的新手.我正在使用VS 2008,C#编写一个RichTextBox. 当我写入RichTextBox时,我想要能够以不同的颜色对每行进行着色.有人可以点我样品吗? 谢谢 foreach (string file in myfiles){ // As I process my files // richTextBox1.Text += "My pro
我是
Windows窗体的新手.我正在使用VS 2008,C#编写一个RichTextBox.
当我写入RichTextBox时,我想要能够以不同的颜色对每行进行着色.有人可以点我样品吗? 谢谢 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 } } 解决方法
在添加之前设置SelectionColor,像:
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 + "rn"); line++; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |