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中实现括号匹配功能。
private int m_lastCaretPos =;
protected override void OnUpdateUI(UpdateUIEventArgs e)
{
base.OnUpdateUI(e);
MatchAndLightBracket();
}
private void MatchAndLightBracket()
{
// Has the caret changed position?
int caretPos = this.CurrentPosition;
if (m_lastCaretPos != caretPos)
{
m_lastCaretPos = caretPos;
int bracePos1 = -;
int bracePos2 = -; // Is there a brace to the left or right?
if (caretPos > && IsBrace(this.GetCharAt(caretPos - )))
bracePos1 = (caretPos - );
else if (IsBrace(this.GetCharAt(caretPos)))
bracePos1 = caretPos; if (bracePos1 >= )
{
// Find the matching brace
bracePos2 = this.BraceMatch(bracePos1);
if (bracePos2 == CodeEditor.InvalidPosition)
{
ReleaseHighlightB();
}
else
{
ReleaseHighlightB();
HighlightBracket(bracePos1);
HighlightBracket(bracePos2);
}
}
else
{
ReleaseHighlightB();
}
}
}
private void HighlightBracket(int pos)
{
if (pos < )
return;
this.IndicatorFillRange(pos, );
}
private void ReleaseHighlightB()
{
this.IndicatorClearRange(, this.TextLength);
}
private static bool IsBrace(int c)
{
switch (c)
{
case '(':
case ')':
case '[':
case ']':
case '{':
case '}':
case '<':
case '>':
return true;
} return false;
}
3. Ctrl+Z会一次性清空所有的修改
protected override void OnBeforeInsert(BeforeModificationEventArgs e)
{
base.OnBeforeInsert(e);
Count = this.Text.Length;
this.BeginUndoAction();
}
protected override void OnInsert(ModificationEventArgs e)
{
base.OnInsert(e);
if (Count < this.Text.Length)
this.EndUndoAction();
}
4.缩进调整
protected override void OnCharAdded(CharAddedEventArgs e)
{
base.OnCharAdded(e);
AutoIndicator();
}
private void AutoIndicator()
{
int pos = this.CurrentPosition;
if (pos > && this.GetCharAt(pos - ) == '\n' && this.GetCharAt(pos - ) == '\r')
{
if (this.GetCharAt(pos - ) == '{')
{
string[] Text = GetStringList();
string line = Text[this.CurrentLine - ];
int start = line.IndexOf(line.TrimStart());
string ss = line.Substring(, start);
string str = new string(' ',);
this.InsertText(pos, ss+str);
this.SelectionStart = this.SelectionEnd = pos + ss.Length + ;
}
else
{
string[] Text = GetStringList();
string line = Text[this.CurrentLine - ];
int start = line.IndexOf(line.TrimStart());
string ss = line.Substring(, start);
this.InsertText(pos, ss);
this.SelectionStart = this.SelectionEnd = pos + ss.Length;
} }
}
private string[] GetStringList()
{
string[] s = new string[] { "\n" };
return this.Text.Split(s, StringSplitOptions.None);
}
目前整理了这么多,有机会再继续深入理解和应用ScintillaNET。
ScintillaNET的应用的更多相关文章
- WinForm搭载ScintillaNET时文本由于发生偏移被隐藏解决方案
项目用ScintillaNet搭载到WinForm以满足文本编辑的需求,在用FindReplace.Scintilla.Text=“显示内容”输出文本内容的时候会碰到文本被WinForm边框隐藏的情况 ...
- DotNet 资源大全中文版(Awesome最新版)
Awesome系列的.Net资源整理.awesome-dotnet是由quozd发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. 算法与数据结构 ...
- C#开源
商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7-SDK E ...
- C# 开源项目一
商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7-SDK E ...
- C#开源大全--汇总(转)
商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7-SDK E ...
- C#开源大全--汇总
商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7-SDK E ...
- C#源码大汇总
C#高仿QQ2013可在广域网部署聊天系统GG叽叽 动态显示硬盘分区容量饼图 自定义ProgressBar控件高仿Win8进度条 多皮肤精美在线QQ悬浮客服插件 jQuery仿天猫首页多格焦点图片轮播 ...
- C#开源汇总
原文:C#开源汇总 商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Pho ...
- C# 网上收集的一些所谓的开源项目
C#开源 商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7- ...
随机推荐
- Maximum Product Subarray LT152
Given an integer array nums, find the contiguous subarray within an array (containing at least one n ...
- mongoDB(Window)
1.启动命令 mongod --dbpath F:\mongo\data 注:dbpath路径不能有空格,我开始用F:\Program Files,就因为有一个空格,失败了. ...
- R.java的生成规则
0x7f010000 开头的是attr 0x7f050000 开头的是anim 0x7f0b0002 开头的是bool 0x7f020000 开头的是drawable 0x7f060000 开头的是i ...
- JDK8集合类源码解析 - ArrayList
ArrayList主要要注意以下几点: 1构造方法 2添加add(E e) 3 获取 get(int index) 4 删除 remove(int index) , remove(Objec ...
- AnsiToUtf8 和 Utf8ToAnsi
在服务端数据库的处理当中,涉及中文字符的结构体字段,需要转为Utf8后再存储到表项中.从数据库中取出包含中文字符的字段后,如果需要保存到char *类型的结构体成员中,需要转为Ansi后再保存.从数据 ...
- java线程池实例
目的 了解线程池的知识后,写个线程池实例,熟悉多线程开发,建议看jdk线程池源码,跟大师比,才知道差距啊O(∩_∩)O 线程池类 package thread.pool2; impor ...
- 【转载】为什么任何随便输入的账号使用SYSDBA权限都能登陆oracle
其实简单点就是检查一下你的机器有没有一个ora_dba用户组,而且你登陆os的用户是否在这个组里,有的话问题的原因就找到了,下面是转的高手的介绍 本文环境配置:Oracle10gR2,Windows ...
- 使用policheck 检测
Policheck is a profing and testing tool for sensitive terminology and helps in ensuring thattrustwor ...
- ubuntu禁用n卡驱动(进系统卡死)
显卡驱动 该发行版依旧内置了Nouveau 开源驱动,这是导致频繁死机的直接原因.接下来要做的三件事情是: 禁用Nouveau 内核模块 安装Intel HD 530 驱动(二选一) 安装NVIDIA ...
- 学会谈判zz
经常有人问我,为什么谈判到你手里就变得那么容易?你有什么诀窍?其实只要是谈判,涉及双方利益,就绝不会轻松.之所以能谈判成功,仔细想想秘诀无非是两个字:“双赢”.要想成功,就要双方都受益.如果你一开始就 ...