【发布时间】:2016-04-20 05:00:46
【问题描述】:
我正在编写一个 c# Html 编辑器应用程序,您可以在其中键入 RichTextBox 控件中的代码。我希望 RichTextBox 的行为类似于 notepad++ 和其他代码编辑器,其中 Html 语法以颜色突出显示,例如:
如何在 C# 窗口中从 RichTextBox 中建立它?我几乎到处搜索,没有找到任何对我有帮助的东西。这是我迄今为止尝试过的,但我没有给出我想要的结果:
private void SyntaxHighlight()
{
string[] tags = { "html","head","body","a","b","img","strong","p","h1","h2","h3","h4","h5","h6","embed","iframe","span","form",
"button","input","textarea","br","div","style","script","table","tr","td","th","i","u","link","meta","title"};
foreach (string s in tags)
{
richTextBox1.Find("<" + s);
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.Find(">");
richTextBox1.SelectionColor = Color.Blue;
}
string[] attributes = { "href","src","height","width","rowspan","colspan","target","style","onclick","id","name","class"};
foreach (string s in attributes)
{
richTextBox1.Find(s + "=");
richTextBox1.SelectionColor = Color.Red;
}
}
有人可以帮助我吗?我应该在 SyntaxHighlight() 方法中写什么?有人可以给我适当的代码吗? 谢谢
【问题讨论】:
-
您查看过this 问题及其解决方案吗?
-
@fujiFX 是的,但这不是我想要的,我想突出显示文本而不是背景
-
您提供的代码得到了什么结果?
标签: c# .net regex richtextbox syntax-highlighting