Mono.TextEditor highlight line

≡放荡痞女 提交于 2019-12-11 11:33:13

问题


I am making a pascal code editor in Mono in MonoDevelop. I am using Mono.TextEditor as a code editor widget. However, I cannot find how to highlight a line in the widget. After compilation, I collect line numbers where errors occur, and so I want to highlight them in red. I found

Mono.TextEditor.LineBackgroundMarker

which seems to relate to what I want to do, but I cannot find where and how to use it.

Another option I was looking into was ViBuilder, but I don't even know how to use that. I can think of two ways to solve this problem:

  1. Simply make highlight
  2. Mark a line as error, as default style includes:

    { "name": "Underline(Error)", "color":"invalid-red" }

which also seems to be a possible solution.


回答1:


You can highlight lines in the text editor by adding markers to the underlying document. Use the TextDocument.AddMarker method, as follows:

TextEditor textEditor;
var marker = new Mono.TextEditor.LineBackgroundMarker();     
int lineNumber = ...;
textEditor.Document.AddMarker(lineNumber, marker);
textEditor.QueueDraw();

Also have a look at the Mono.TextEditor.StyleTextMarker class. This class has already the properties "BackgroundColor" / "Color" that you are looking for. Underlining may have to be done manually (for example by inheriting from StyleTextMarker and overriding the Draw method).



来源:https://stackoverflow.com/questions/15660859/mono-texteditor-highlight-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!