ScintillaNET的应用

  出于工作需要,需要制作一个嵌入在桌面应用中的C语言编辑器,经过一系列调研,目前ScintillaNET应该是最合适的了,开源、轻便、功能丰富,但是踩得坑也很多,接下面一一说道。

  目前ScintillaNET托管在https://github.com/jacobslusser/ScintillaNET,拉下来重新编译。由于需要移植到.NET 2.0的平台上,需要修改源码中的对Linq的依赖,这里不多说,把目标框架改为.NET 2.0,编译,哪里报错改哪里。

1. 编辑器风格

参考:https://github.com/robinrodricks/ScintillaNET.Demo

2. 括号的匹配和高亮

为了方便多处调用该控件,继承Scintilla类,实现“自定义”控件,以下均以这种做法来实现功能。

重写OnUpdateUI事件,在UpdateUI中实现括号匹配功能。

 1 private int m_lastCaretPos =0;
 2 protected override void OnUpdateUI(UpdateUIEventArgs e)
 3 {
 4     base.OnUpdateUI(e);
 5     MatchAndLightBracket();
 6 }
 7 private void MatchAndLightBracket()
 8  {
 9     // Has the caret changed position?
10     int caretPos = this.CurrentPosition;
11     if (m_lastCaretPos != caretPos)
12     {
13         m_lastCaretPos = caretPos;
14         int bracePos1 = -1;
15         int bracePos2 = -1;
16 
17         // Is there a brace to the left or right?
18         if (caretPos > 0 && IsBrace(this.GetCharAt(caretPos - 1)))
19              bracePos1 = (caretPos - 1
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值