如何使用ICSharpCode.TextEditor.TextEditorControl突出显示语法错误?

Igo*_*huk 6 sharpdevelop icsharpcode

我正在使用ICSharpCode.TextEditor.TextEditorControl我的DSL编辑器.当我收到DSL编译错误时,我想突出显示有问题的文本以提供更好的用户体验.但是,我很难找到如何做到这一点.

到目前为止,我发现有一个ShowInvalidLines属性,但我没有看到将任何行标记为无效的方法.我也看到HighlightSpanStack财产LineSegmentHighlightingStrategy,但不知道他们应该如何使用.

任何帮助,将不胜感激.谢谢!

Mat*_*ard 12

要突出显示一段文本,请使用TextMarker.以下代码使用红色波浪线突出显示"错误"一词.

TextEditorControl textEditor = new TextEditorControl();
textEditor.Text = "Mark Error";

int offset = 5;
int length = 5;
TextMarker marker = new TextMarker(offset, length, TextMarkerType.WaveLine, Color.Red);
textEditor.Document.MarkerStrategy.AddMarker(marker);
Run Code Online (Sandbox Code Playgroud)

您可以使用任何背景和前景颜色突出显示文本,TextMarkerType支持下划线,波浪线或实心颜色块.