Adding text at pointer-position via code

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Radjesh Klauke - Mr., X-impress
Version: 4.0.0288
Avatar
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 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
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 13 years ago by Radjesh Klauke - Mr., X-impress
Avatar
Thanks. It works.

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

Add Comment

Please log in to a validated account to post comments.