Adding text at pointer-position via code

SyntaxEditor for Windows Forms Forum

Posted 9 years ago by Radjesh Klauke - Mr., X-impress
Version: 4.0.0288
Still not done with the lexer etc, but atm. I'm trying to add text via code, but it seems that it doesn't work as the standard textbox/RTB do.
With Textbox1
   Dim insertText = "test"
   Dim insertPos As Integer = .SelectionStart
   .Text = .Text.Insert(insertPos, insertText)
   .SelectionStart = insertPos + insertText.Length
End With
Which property of the editor do I need to exam to get the same result?

Thanks in advance.

[Modified at 02/08/2011 01:45 AM]

Comments (2)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
If you're just trying to replace the selected text it would be something like:
editor.SelectedView.SelectedText = insertText;
Alternatively you could do something like this:
editor.Document.InsertText(DocumentModificationType.Typing, editor.SelectedView.Selection.EndOffset, insertText);
Note that editor.SelectedView.Selection.EndOffset is where the caret is (same as editor.Caret.Offset). editor.SelectedView.Selection.StartOffset is the anchor of the selection.

[Modified at 02/07/2011 03:13 PM]

Actipro Software Support

Posted 9 years ago by Radjesh Klauke - Mr., X-impress
Thanks. It works.

[Modified at 02/08/2011 01:44 AM]
The latest build of this product (v2020.1 build 0401) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.