)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to insert selected text within XML tag in WinForms SyntaxEditor (EditControl)?

Platform: WinForms |
Control: EditControl |
Published Date: February 4, 2015 |
Last Revised Date: December 11, 2019

Add or remove the lines

In EditControl, you can load the selected text inside XML tag by using “SelectedText”, “Selection” properties and “InsertText”, “DeleteText” functions.

The following code example illustrates the same.

C#

//Gets the selected text
string selectedText = editControl1.SelectedText;
//Delete the selected text
editControl1.DeleteText(editControl1.Selection.Top, editControl1.Selection.Bottom);
//Gets the cursor position
IParsePoint iparse = editControl1.GetRealCursorPosition();
int cursorposition = iparse.Position;
if (flag)
{
    cursorposition = cursorposition - 1;
}
//Inserting before
editControl1.InsertText(iparse.Line, cursorposition, "#region\n");
iparse = editControl1.GetRealCursorPosition();
if (flag)
{
    //Inserting selected text
    editControl1.InsertText(iparse.Line, cursorposition - 1, selectedText + "\n");
    flag = false;
}
else
    //Inserting selected text
    editControl1.InsertText(iparse.Line, cursorposition, selectedText + "\n");
iparse = editControl1.GetRealCursorPosition();
//Inserting text at end of the selection
editControl1.InsertText(iparse.Line, cursorposition, "#endregion");

VB

'Gets the selected text
Dim selectedText As String = editControl1.SelectedText
'Delete the selected text
editControl1.DeleteText(editControl1.Selection.Top, editControl1.Selection.Bottom)
'Gets the cursor position
Dim iparse As IParsePoint = editControl1.GetRealCursorPosition()
Dim cursorposition As Integer = iparse.Position
If flag Then
 cursorposition = cursorposition - 1
End If
'Inserting before
editControl1.InsertText(iparse.Line, cursorposition, "#region" & Constants.vbLf)
iparse = editControl1.GetRealCursorPosition()
If flag Then
 'Inserting selected text
 editControl1.InsertText(iparse.Line, cursorposition - 1, selectedText & Constants.vbLf)
 flag = False
Else
 'Inserting selected text
 editControl1.InsertText(iparse.Line, cursorposition, selectedText & Constants.vbLf)
End If
iparse = editControl1.GetRealCursorPosition()
'Inserting text at end of the selection
editControl1.InsertText(iparse.Line, cursorposition, "#endregion"

Sample:

http://www.syncfusion.com/downloads/support/directtrac/general/EditControl_EditLine-587802118.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon