Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何用不同的颜色给RichTextBox中的不同单词上色?_C#_.net_Winforms - Fatal编程技术网

C# 如何用不同的颜色给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 =

如何对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 = 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(“黑色文本”)

结束您使用什么控件显示文本?您有问题吗?我说不出你想要什么我把问题更新到。。。我有个问题。我把它从“行”改为“节”--区别在于选择的不同。给你的答案一些更好的格式和解释