最近遇到的一个项目问题,使用了SharpDevelop中TextEditorControl控件,但在对代码缩进时遇到一个问题,使用默认的设置是无法智能缩进代码的。于是下载了SharpDevelop的源码研究了一下,心得记录下来方便以后使用。自定义一个控件继承自TextEditorControl
public class PDTTextAreaControl : TextEditorControl
{
public PDTTextAreaControl()
: base()
{
Document.FormattingStrategy = (IFormattingStrategy)new CSharpFormattingStrategy();
}
}
文档类Document的格式化策略FormattingStrategy 需要自定义或者使用CSharpFormattingStrategy策略。其中CSharpFormattingStrategy定义在插件CSharpBinding.dll中。
缩进排序时调用一下代码:
textEditorControl1.IndentStyle = IndentStyle.Smart;
IEditAction EditAction = new FormatBuffer();
EditAction.Execute(textEditorControl1.ActiveTextAreaControl.TextArea);
本文介绍如何在SharpDevelop中实现代码智能缩进功能。通过自定义TextEditorControl控件并应用CSharpFormattingStrategy策略,可以有效提升代码编辑体验。
2345

被折叠的 条评论
为什么被折叠?



