Articles in this section
Category / Section

How to implement VS.NET like XML tag insertion feature using WinForms SyntaxEditor (EditControl)?

4 mins read

Text handling

This can be used, while editing the XML language tags in the SyntaxEditor (EditControl).

The cursor can be placed at any positon of the line and the nodes will be inserted correctly in the beginning and the end of the current line. This feature saves time while editing your XML documents using the Essential Edit. Refer to the code attached to know more about it.

C#

private void menuItem_Click(object sender, System.EventArgs e)
{
    this.inputDialog.ShowDialog();
    if(this.accepted == true)
    {
        if(this.inputString.Equals(""))
        {
            MessageBox.Show("The node name cannot be empty");
        }
        else
        {
            this.editControl1.MoveToLineStart();
            this.editControl1.InsertText(this.editControl1.CurrentLine,(this.editControl1.CurrentColumn)," ");
            this.editControl1.InsertTexthis.editControl1.CurrentLine,this.editControl1.CurrentColumn, "<"+this.inputString+">");
            this.editControl1.InsertText(this.editControl1.CurrentLine,(this.editControl1.CurrentColumn)," ");
            this.editControl1.AppendText("</"+this.inputString+">");
        }
    }
}

 

VB

Private Sub menuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menuItem12.Click
     Me.inputDialog.ShowDialog()
     If Me.accepted = True Then
         If Me.inputString.Equals("") Then
             MessageBox.Show("The node name cannot be empty")
         Else
             Me.editControl1.MoveToLineStart()
             Me.editControl1.InsertText(Me.editControl1.CurrentLine,(Me.editControl1.CurrentColumn)," ")
             Me.editControl1.InsertText(Me.editControl1.CurrentLine,Me.editControl1.CurrentColumn, "<"+Me.inputString+">")
             Me.editControl1.InsertText(Me.editControl1.CurrentLine,(Me.editControl1.CurrentColumn)," ")
             Me.editControl1.AppendText("</"+Me.inputString+">")
         End If
     End If
End Sub

 

Reference link: https://help.syncfusion.com/windowsforms/syntaxeditor/editing#text-handling

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