ScintillaNET Control不显示语法着色?

时间:2015-08-12 00:10:50

标签: java c# visual-studio textbox scintilla

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

答案 0 :(得分:0)

这个问题可能已经过时,可能会被关闭,因为在此期间,我在GitHub https://github.com/robinrodricks/ScintillaNET.Demo上创建了一个Demo项目,该项目涵盖了这个示例并且运行正常。

请参阅中的方法InitSyntaxColoring https://github.com/robinrodricks/ScintillaNET.Demo/blob/master/ScintillaNET.Demo/MainForm.cs

Screenshot