C# 如何用不同的颜色给RichTextBox中的不同单词上色?
如何对RichTextBox的部分使用不同的颜色C# 如何用不同的颜色给RichTextBox中的不同单词上色?,c#,.net,winforms,C#,.net,Winforms,如何对RichTextBox的部分使用不同的颜色 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 =
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?
}
string text=“a b c d teste”;
//重点词语
字符串[]单词={“a”、“b”、“c”、“d”};
//要使用的颜色,与上面的文字对齐
Color[]Color={Color.Red,Color.Blue,Color.BlueViolet,Color.Brown};
for(int c=0,size=word.Length;c
您应该使用RichTextBox为文本行着色,请使用此代码段
txtRichTextBox.Select(yourText.IndexOf("portion"), "portion".Length);
txtRichTextBox.SelectionColor = YourColor;
txtRichTextBox.SelectionFont = new Font("Times New Roman",FontStyle.Bold);
Visual Basic代码:
使用RichTextBox1
.SelectionColor=Color.Blue
.AppendText(“蓝色文本”)
.SelectionColor=Color.Black
.AppendText(“黑色文本”)
以结束您使用什么控件显示文本?您有问题吗?我说不出你想要什么我把问题更新到。。。我有个问题。我把它从“行”改为“节”--区别在于选择的不同。给你的答案一些更好的格式和解释