如何颜色不同的词在不同颜色的一个RichTextBox? [英] How to color different words in a RichTextBox with different colors?

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

问题描述

如何着色的一个RichTextBox的部分的不同?

 字符串文本=A B C D睾丸;

//字突出
字符串[]字=​​ {A,B,C,D};

//颜色使用,与上面的字对齐
颜色[]颜色= {Color.Red,Color.Blue,Color.BlueViolet,Color.Brown};

对于(INT C = 0,大小= word.Length; C<大小; C ++){
    //通过颜色[X]搜索和设置线条颜色上色[X]
    //我怎么做到这一点?
}
 

解决方案

你应该使用的RichTextBox到彩色文本行,使用此片段。

  txtRichTextBox.Select(yourText.IndexOf(部分),部分.Length);
txtRichTextBox.SelectionColor = YourColor;
txtRichTextBox.SelectionFont =新的字体(宋体,FontStyle.Bold);
 

How to color sections of a RichTextBox differently?

string text = "a b c d teste";

// words to highlight
string[] word = { "a", "b", "c", "d" };

// colors to use, aligned with words above
Color[] color = { Color.Red, Color.Blue, Color.BlueViolet, Color.Brown };

for(int c = 0,size = word.Length; c < size; c++) {
    //search by color[x] and set line color to color[x]
    //How I do this?
}

解决方案

you should use RichTextBox to color your lines of text, use this snippet.

txtRichTextBox.Select(yourText.IndexOf("portion"), "portion".Length);
txtRichTextBox.SelectionColor = YourColor;
txtRichTextBox.SelectionFont = new Font("Times New Roman",FontStyle.Bold);

这篇关于如何颜色不同的词在不同颜色的一个RichTextBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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