我如何使用C#突出显示RichTextBox中的语法,就像在IDE中完成一样?
如果是这样,我能做这样的事情,还是过于复杂?
public String SyntaxHighlight(string ToHighlight)
{
string Highlighted = null;
List<string> Blue = new List<string>();
Blue.Add("public");
Blue.Add("private");
Blue.Add("static");
Blue.Add("string");
//And so on...
for(int i = 0; i < WordCount(ToHighlight); ++i)
{
foreach(string B in Blue)
if(GetWord(ToHighlight, i) == B)
{
Highlighted += GetWord(ToHighlight, i) // Set Colour Somehow;
}
else
{
Highlighted += GetWord(ToHighlight, i);
}
}
}
public int WordCount(string ToCount)
{
int Count = 0;
for(int i = 0; i < ToCount.Length; ++i)
{
if(ToCount[i].ToString() == " ")
{
Count++;
}
}
return Count;
}
public String GetWord(string From, int WordNum)
{
}
答案 0 :(得分:2)
看看这个。我希望这是你正在寻找的东西:
http://millz12.wordpress.com/2009/11/26/c-richtextbox-syntax-highlighting/
答案 1 :(得分:1)