Loading...
Loading...
Guide for implementing Syncfusion EditControl (SyntaxEditor) in Windows Forms applications. Use when creating interactive code editors with syntax highlighting, IntelliSense, multi-language support, or Visual Studio-like editing capabilities. Covers installation, syntax highlighting for 12+ built-in languages (C#, VB.NET, XML, HTML, Java, SQL, PowerShell, JavaScript), custom language configuration, code outlining, auto-completion, find/replace dialogs, file operations, export (XML/RTF/HTML), split views, and comprehensive event handling for building professional code editor applications.
npx skill4agent add syncfusion/winforms-ui-components-skills syncfusion-winforms-syntax-editorEditControlSyncfusion.Windows.Forms.EditSyncfusion.Edit.Windows.dllSyncfusion.Tools.Windows.dllSyncfusion.Shared.Base.dllApplyConfiguration()KnownLanguagesLoadFile()Save()SaveAs()using Syncfusion.Windows.Forms.Edit;
using Syncfusion.Windows.Forms.Edit.Enums;
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
public class CodeEditorForm : Form
{
private EditControl editControl1;
public CodeEditorForm()
{
InitializeComponent();
SetupCodeEditor();
}
private void SetupCodeEditor()
{
// Create EditControl
editControl1 = new EditControl();
// Basic configuration
editControl1.Dock = DockStyle.Fill;
editControl1.BorderStyle = BorderStyle.Fixed3D;
// Apply C# syntax highlighting
editControl1.ApplyConfiguration(KnownLanguages.CSharp);
// Enable line numbers
editControl1.ShowLineNumbers = true;
// Enable code outlining
editControl1.ShowOutliningCollapsers = true;
// Add to form
this.Controls.Add(editControl1);
// Load sample code (optional)
string sampleCode = @"using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(""Hello, World!"");
}
}
}";
editControl1.Text = sampleCode;
}
private void InitializeComponent()
{
this.Text = "C# Code Editor";
this.Size = new Size(800, 600);
}
}Imports Syncfusion.Windows.Forms.Edit
Imports Syncfusion.Windows.Forms.Edit.Enums
Imports System
Imports System.Drawing
Imports System.IO
Imports System.Windows.Forms
Public Class CodeEditorForm
Inherits Form
Private editControl1 As EditControl
Public Sub New()
InitializeComponent()
SetupCodeEditor()
End Sub
Private Sub SetupCodeEditor()
' Create EditControl
editControl1 = New EditControl()
' Basic configuration
editControl1.Dock = DockStyle.Fill
editControl1.BorderStyle = BorderStyle.Fixed3D
' Apply C# syntax highlighting
editControl1.ApplyConfiguration(KnownLanguages.CSharp)
' Enable line numbers
editControl1.ShowLineNumbers = True
' Enable code outlining
editControl1.ShowOutliningCollapsers = True
' Add to form
Me.Controls.Add(editControl1)
' Load sample code (optional)
Dim sampleCode As String = "using System;" & vbCrLf & vbCrLf & _
"namespace HelloWorld" & vbCrLf & _
"{" & vbCrLf & _
" class Program" & vbCrLf & _
" {" & vbCrLf & _
" static void Main(string[] args)" & vbCrLf & _
" {" & vbCrLf & _
" Console.WriteLine(""Hello, World!"");" & vbCrLf & _
" }" & vbCrLf & _
" }" & vbCrLf & _
"}"
editControl1.Text = sampleCode
End Sub
Private Sub InitializeComponent()
Me.Text = "C# Code Editor"
Me.Size = New Size(800, 600)
End Sub
End Classprivate ComboBox languageSelector;
private EditControl editControl1;
private void SetupMultiLanguageEditor()
{
// Language selector
languageSelector = new ComboBox
{
Dock = DockStyle.Top,
DropDownStyle = ComboBoxStyle.DropDownList
};
languageSelector.Items.AddRange(new object[]
{
"C#", "VB.NET", "XML", "HTML", "Java", "SQL", "PowerShell", "JavaScript"
});
languageSelector.SelectedIndex = 0;
languageSelector.SelectedIndexChanged += LanguageSelector_SelectedIndexChanged;
// Editor
editControl1 = new EditControl
{
Dock = DockStyle.Fill,
ShowLineNumbers = true,
ShowOutliningCollapsers = true
};
this.Controls.Add(editControl1);
this.Controls.Add(languageSelector);
// Apply initial language
ApplyLanguage("C#");
}
private void LanguageSelector_SelectedIndexChanged(object sender, EventArgs e)
{
ApplyLanguage(languageSelector.SelectedItem.ToString());
}
private void ApplyLanguage(string language)
{
switch (language)
{
case "C#":
editControl1.ApplyConfiguration(KnownLanguages.CSharp);
break;
case "VB.NET":
editControl1.ApplyConfiguration(KnownLanguages.VB);
break;
case "XML":
editControl1.ApplyConfiguration(KnownLanguages.XML);
break;
case "HTML":
editControl1.ApplyConfiguration(KnownLanguages.HTML);
break;
case "Java":
editControl1.ApplyConfiguration(KnownLanguages.Java);
break;
case "SQL":
editControl1.ApplyConfiguration(KnownLanguages.SQL);
break;
case "PowerShell":
editControl1.ApplyConfiguration(KnownLanguages.PowerShell);
break;
case "JavaScript":
editControl1.ApplyConfiguration(KnownLanguages.JScript);
break;
}
}private EditControl editControl1;
private string currentFilePath = null;
private void SetupFileEditor()
{
editControl1 = new EditControl
{
Dock = DockStyle.Fill,
ShowLineNumbers = true
};
// Menu bar
MenuStrip menuStrip = new MenuStrip();
ToolStripMenuItem fileMenu = new ToolStripMenuItem("File");
fileMenu.DropDownItems.Add("New", null, NewFile_Click);
fileMenu.DropDownItems.Add("Open...", null, OpenFile_Click);
fileMenu.DropDownItems.Add("Save", null, SaveFile_Click);
fileMenu.DropDownItems.Add("Save As...", null, SaveFileAs_Click);
menuStrip.Items.Add(fileMenu);
this.Controls.Add(editControl1);
this.Controls.Add(menuStrip);
this.MainMenuStrip = menuStrip;
}
private void NewFile_Click(object sender, EventArgs e)
{
editControl1.Text = string.Empty;
currentFilePath = null;
this.Text = "Untitled - Code Editor";
}
private void OpenFile_Click(object sender, EventArgs e)
{
OpenFileDialog openDialog = new OpenFileDialog
{
Filter = "All Files (*.*)|*.*|C# Files (*.cs)|*.cs|VB Files (*.vb)|*.vb"
};
if (openDialog.ShowDialog() == DialogResult.OK)
{
editControl1.LoadFile(openDialog.FileName);
currentFilePath = openDialog.FileName;
this.Text = Path.GetFileName(currentFilePath) + " - Code Editor";
// Auto-detect language based on extension
string ext = Path.GetExtension(currentFilePath).ToLower();
if (ext == ".cs")
editControl1.ApplyConfiguration(KnownLanguages.CSharp);
else if (ext == ".vb")
editControl1.ApplyConfiguration(KnownLanguages.VB);
else if (ext == ".xml")
editControl1.ApplyConfiguration(KnownLanguages.XML);
}
}
private void SaveFile_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(currentFilePath))
{
SaveFileAs_Click(sender, e);
}
else
{
editControl1.Save(currentFilePath);
}
}
private void SaveFileAs_Click(object sender, EventArgs e)
{
SaveFileDialog saveDialog = new SaveFileDialog
{
Filter = "All Files (*.*)|*.*|C# Files (*.cs)|*.cs|VB Files (*.vb)|*.vb"
};
if (saveDialog.ShowDialog() == DialogResult.OK)
{
editControl1.Save(saveDialog.FileName);
currentFilePath = saveDialog.FileName;
this.Text = Path.GetFileName(currentFilePath) + " - Code Editor";
}
}editControl1 = new EditControl { Dock = DockStyle.Fill, ShowLineNumbers = true };
editControl1.ApplyConfiguration(KnownLanguages.CSharp);
// Add auto-complete items
editControl1.AutoCompleteList.AddRange(new[] { "Console", "Console.WriteLine",
"string", "int", "public", "private", "class" });
// Enable auto-correct
editControl1.AutoCorrectList.Add("teh", "the");
editControl1.AutoCorrectList.Add("cosole", "console");
this.Controls.Add(editControl1);| Property | Type | Description |
|---|---|---|
| Text | | Gets or sets the text content of the editor |
| ShowLineNumbers | | Shows or hides line numbers in the margin |
| ShowOutliningCollapsers | | Enables code outlining collapse/expand controls |
| WordWrap | | Enables or disables word wrapping |
| ReadOnly | | Makes the editor read-only |
| TabSize | | Sets the number of spaces for tab character |
| AutoCompleteMode | | Configures auto-complete behavior (All, Suggest, None) |
| EnableAutoCorrect | | Enables automatic correction of common typos |
| StatusBarSettings | | Configures the built-in status bar |
| ContextChoiceOpen | | Gets whether IntelliSense context menu is open |
| CanUndo | | Indicates if undo operation is available |
| CanRedo | | Indicates if redo operation is available |
| Modified | | Indicates if the document has been modified |
| Method | Description |
|---|---|
| ApplyConfiguration(KnownLanguages) | Applies built-in syntax highlighting configuration |
| LoadFile(string) | Loads a file into the editor |
| Save(string) | Saves the current content to a file |
| SaveAs(string) | Saves content to a new file |
| Undo() | Performs undo operation |
| Redo() | Performs redo operation |
| Cut() | Cuts selected text to clipboard |
| Copy() | Copies selected text to clipboard |
| Paste() | Pastes text from clipboard |
| SelectAll() | Selects all text in the editor |
| Find() | Opens the find dialog |
| Replace() | Opens the replace dialog |
| GoToLine(int) | Navigates to specified line number |
| SetText(string) | Sets text content programmatically |
| Export(string, ExportType) | Exports content to XML, RTF, or HTML |
| Print() | Opens print dialog for the document |