ScintillaNET 控件不显示语法着色?

Posted

技术标签:

【中文标题】ScintillaNET 控件不显示语法着色?【英文标题】:ScintillaNET Control not displaying syntax coloring? 【发布时间】:2015-08-12 00:10:49 【问题描述】:

我通过 Nuget 包管理器在我的项目中安装了 ScintillaNET 包。然后我通过添加已安装的 Scintilla dll 的路径(通过右键单击工具箱 > 选择项目 > 浏览)使 Scintilla 文本框控件出现在工具框中。我提到了我的安装过程,因为网上的人在设置这个东西时遇到了很多麻烦。现在到了真正的问题,当我将控件拖到窗体上时,会出现一个文本框,但即使将Lexer 属性设置为cpp,我也无法让它显示语法着色。如文档中所示以编程方式执行此操作也不起作用。以下是我使用的代码(scintilla 是闪烁控件的名称):

 // Configuring the default style with properties
 // we have common to every lexer style saves time.
scintilla.StyleResetDefault();
scintilla.Styles[Style.Default].Font = "Consolas";
scintilla.Styles[Style.Default].Size = 10;
scintilla.StyleClearAll();

// Configure the CPP (C#) lexer styles
scintilla.Styles[Style.Cpp.Default].ForeColor = Color.Silver;
scintilla.Styles[Style.Cpp.Comment].ForeColor = Color.FromArgb(0, 128, 0); // Green
scintilla.Styles[Style.Cpp.CommentLine].ForeColor = Color.FromArgb(0, 128, 0); // Green
scintilla.Styles[Style.Cpp.CommentLineDoc].ForeColor = Color.FromArgb(128, 128, 128); // Gray
scintilla.Styles[Style.Cpp.Number].ForeColor = Color.Olive;
scintilla.Styles[Style.Cpp.Word].ForeColor = Color.Blue;
scintilla.Styles[Style.Cpp.Word2].ForeColor = Color.Blue;
scintilla.Styles[Style.Cpp.String].ForeColor = Color.FromArgb(163, 21, 21); // Red
scintilla.Styles[Style.Cpp.Character].ForeColor = Color.FromArgb(163, 21, 21); // Red
scintilla.Styles[Style.Cpp.Verbatim].ForeColor = Color.FromArgb(163, 21, 21); //   Red
scintilla.Styles[Style.Cpp.StringEol].BackColor = Color.Pink;
scintilla.Styles[Style.Cpp.Operator].ForeColor = Color.Purple;
scintilla.Styles[Style.Cpp.Preprocessor].ForeColor = Color.Maroon;
scintilla.Lexer = Lexer.Cpp;

// Set the keywords
scintilla.SetKeywords(0, "abstract as base break case catch checked continue   default delegate do else event explicit extern false finally fixed for foreach goto if implicit in interface internal is lock namespace new null object operator out override params private protected public readonly ref return sealed sizeof stackalloc switch this throw true try typeof unchecked unsafe using virtual while");

此代码直接来自 Scintilla documentation。我正在使用 Visual Studio 2013 Express。

【问题讨论】:

【参考方案1】:

这个问题可能已经过时并且可以关闭,因为同时在 GitHub https://github.com/robinrodricks/ScintillaNET.Demo 上创建了 Demo 项目,它涵盖了这个示例并且运行良好。

见方法InitSyntaxColoring in https://github.com/robinrodricks/ScintillaNET.Demo/blob/master/ScintillaNET.Demo/MainForm.cs

Screenshot

【讨论】:

以上是关于ScintillaNET 控件不显示语法着色?的主要内容,如果未能解决你的问题,请参考以下文章

语法高亮:.NET 的富文本框控件

在 ScintillaNET 控件中实现块注释/取消注释

ScintillaNET 自动完成列表问题

ScintillaNet - 计算出用户点击了哪一行

如何将光标移动到 ScintillaNet 控件中特定行的特定位置?

从 ScintillaNet 打印内容时打印行号