Articles in this section

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

Add or remove the lines


In WinForms EditControl, you can load the selected text inside XML tag by using “SelectedText”, “Selection” properties as well as the “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:

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


Conclusion

I hope you enjoyed learning on how to insert selected text within XML tag in WinForms SyntaxEditor (EditControl).

You can refer to WinForms Syntax Editor feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Syntax Editor example to understand how to create and manipulate data.

For current customers, you can check out our components from the  License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied