3

我正在尝试在 ICSharpCode TextEditor 中选择文本行。以及使文本框转到特定行。该应用程序是用 C# 在 VS 2010 中构建的 Windows 窗体应用程序。

我使用文本编辑器的原因是代码突出显示和行号等。

我真的没有太多使用 Windows 窗体的经验,所以任何帮助将不胜感激。我的代码如下:

textEditorControl.Text = "long file string with line breaks";
textEditorControl.VRulerRow = 10; //Example row selection
4

1 回答 1

5

以下是如何使用 SharpDevelop 3.2 附带的文本编辑器选择文本的示例:

// Two lines of text.
textEditorControl.Text = 
    "First\r\n" +
    "Second\r\n";

// Start of selection - columns and lines are zero based.
int startCol = 0;
int startLine = 1;
TextLocation start = new TextLocation(startCol, startLine);

// End of selection.
int endCol = 6;
int endLine = 1;
TextLocation end = new TextLocation(endCol, endLine);

// Select the second line.
textEditorControl.ActiveTextAreaControl.SelectionManager.SetSelection(start, end);

// Move cursor to end of selection.
textEditorControl.ActiveTextAreaControl.Caret.Position = end;

我假设“使文本框转到特定行”是指将光标移动到该行。上面示例中的最后一行代码向您展示了如何做到这一点。

于 2010-08-14T17:02:57.490 回答