我想知道如何更改richtextbox中某些字符的颜色。
我想更改四个关键词的颜色:
"CONDITION","FIRSTCONDITION","SECONDCONDITION","ACTION"
这是我在Richtext框中的文本
"If (CONDITION) then"
"And (FIRSTCONDITION)&(SECONDCONDITION)"
"While (CONDITION) do(ACTION)"
最后我的代码
public Form1()
{
InitializeComponent();
}
private void MyRichTextBox(object sender, EventArgs e)
{
richTextBox1.Font = new Font("Arial", 12f, FontStyle.Bold);
string[] words =
{ "If (CONDITION) then","And (FIRSTCONDITION)&(SECONDCONDITION)",
"While (CONDITION) do(ACTION)"
};
for (int i = 0; i < words.Length; i++)
{
string word = words[i];
{
richTextBox1.AppendText(word);
}
}
MyRichTextBox.Settings.Keywords.Add("CONDITION");
MyRichTextBox.Settings.Keywords.Add("FIRSTCONDITION");
MyRichTextBox.Settings.Keywords.Add("SECONDCONDITION");
MyRichTextBox.Settings.Keywords.Add("ACTION");
MyRichTextBox.Settings.KeywordColor = Color.Blue;
}
谢谢你的帮助。