详细介绍一款.NET代码编辑控件(ICSharpCode.TextEditor)


当前第2页 返回上一页

拷贝CSharp-Mode.xshd为 JackCSharp-Mode.xshd ,将其中的名字修改为: SyntaxDefinition name = "JackC#" ,并添加高亮关键字,如下:

这样代码中出现的JackWang就会高亮。下面的代码片段将自定义高亮文件进行加载,并用SetHighlighting进行设置,这里一定注意目录下必须有xshd的配置文件,否则高亮将失效。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

textEditor.Encoding = System.Text.Encoding.UTF8;

 textEditor.Font = new Font("Hack",12);

 textEditor.Document.FoldingManager.FoldingStrategy = new JackWangCUMT.WinForm.MingFolding();

 textEditor.Text = sampleCode;

 

 //自定义代码高亮

 string path = Application.StartupPath+ "\\HighLighting";

 FileSyntaxModeProvider fsmp;

 if (Directory.Exists(path))

 {

  fsmp = new FileSyntaxModeProvider(path);

  HighlightingManager.Manager.AddSyntaxModeFileProvider(fsmp);

  textEditor.SetHighlighting("JackC#");

 }

为了保持代码适时进行折叠,这里监听文本变化,如下所示:

1

2

3

4

5

private void TextEditor_TextChanged(object sender, EventArgs e)

{

 //更新,以便进行代码折叠

 textEditor.Document.FoldingManager.UpdateFoldings(null, null);

}

最后说明的是,我们可以定义一个格式化代码的类,来格式化C#代码:

总结

【相关推荐】

1. ASP.NET免费视频教程

2. ASP.NET教程

3. 极客学院ASP.NET视频教程

以上就是详细介绍一款.NET代码编辑控件(ICSharpCode.TextEditor)的详细内容!

返回前面的内容

相关阅读 >>

两个需要在asp.net程序中值得注意的地方

iis如何实现部署asp.net mvc网站的方法

详解《asp.net》数据绑定―datalist

asp.net完成文件上传的代码教程

asp.net(一)基础三层框架项目:web服务器、业务服务器、数据库服务器

asp.net core中关于webapi几种版本控制对比详解(图)

asp.net中实现des加密与解密md5加密功能介绍

asp.net通过remoting service上传文件的实例详解

asp.net页脚制作详解

asp.net部署到iis常见问题的解决方法_实用技巧

更多相关阅读请进入《asp.net》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...