Category / Section
How to implement the SelectionMargin feature in WinForms SyntaxEditor (EditControl)?
2 mins read
Selection margin feature
This feature helps the user in setting the SelectionMargin's BackColor, FrontColor and the Width of the margin, which helps to create a more user-friendly environment. Please refer the below code, to know more about it.
C#
private void Width_menuItem_Click(object sender, System.EventArgs e) { MenuItem item = sender as MenuItem; if (item.Text == "25") this.editControl1.SelectionMarginWidth = 25; else if (item.Text == "50") this.editControl1.SelectionMarginWidth = 50; else if (item.Text == "75") this.editControl1.SelectionMarginWidth = 75; else if (item.Text == "100") this.editControl1.SelectionMarginWidth = 100; else if (item.Text == "125") this.editControl1.SelectionMarginWidth = 125; } private void BackgroundColor_menuItem_Click(object sender, System.EventArgs e) { MenuItem item = sender as MenuItem; if (item.Text == "LightBlue") this.editControl1.SelectionMarginBackgroundColor = Color.LightBlue; else if (item.Text == "IndianRed") this.editControl1.SelectionMarginBackgroundColor = Color.IndianRed; else if (item.Text == "Beige") this.editControl1.SelectionMarginBackgroundColor = Color.Beige; } private void ForegroundColor_menuItem_Click(object sender, System.EventArgs e) { MenuItem item = sender as MenuItem; if (item.Text == "Gray") this.editControl1.SelectionMarginForegroundColor = Color.Gray; else if (item.Text == "Maroon") this.editControl1.SelectionMarginForegroundColor = Color.Maroon; else if (item.Text == "Navy") this.editControl1.SelectionMarginForegroundColor = Color.Navy; }
VB
Private Sub Width_menuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim item As MenuItem = TryCast(sender, MenuItem) If item.Text = "25" Then Me.editControl1.SelectionMarginWidth = 25 ElseIf item.Text = "50" Then Me.editControl1.SelectionMarginWidth = 50 ElseIf item.Text = "75" Then Me.editControl1.SelectionMarginWidth = 75 ElseIf item.Text = "100" Then Me.editControl1.SelectionMarginWidth = 100 ElseIf item.Text = "125" Then Me.editControl1.SelectionMarginWidth = 125 End If End Sub 'Width_menuItem_Click Private Sub BackgroundColor_menuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim item As MenuItem = TryCast(sender, MenuItem) If item.Text = "LightBlue" Then Me.editControl1.SelectionMarginBackgroundColor = Color.LightBlue ElseIf item.Text = "IndianRed" Then Me.editControl1.SelectionMarginBackgroundColor = Color.IndianRed ElseIf item.Text = "Beige" Then Me.editControl1.SelectionMarginBackgroundColor = Color.Beige End If End Sub 'BackgroundColor_menuItem_Click Private Sub ForegroundColor_menuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim item As MenuItem = TryCast(sender, MenuItem) If item.Text = "Gray" Then Me.editControl1.SelectionMarginForegroundColor = Color.Gray ElseIf item.Text = "Maroon" Then Me.editControl1.SelectionMarginForegroundColor = Color.Maroon ElseIf item.Text = "Navy" Then Me.editControl1.SelectionMarginForegroundColor = Color.Navy End If End Sub 'ForegroundColor_menuItem_Click
Reference link: https://help.syncfusion.com/windowsforms/syntaxeditor/appearance#selection-margin