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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I implement the SelectionMargin feature in EditControl?

Platform: WinForms |
Control: EditControl |
Published Date: April 30, 2011 |
Last Revised Date: July 10, 2014


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.

Refer to the code below and the attached sample, to know more about it.


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;



Private Sub Width_menuItem_Click(sender As Object, e As System.EventArgs) Handles menuItem13.Click, menuItem14.Click, menuItem15.Click, menuItem16.Click, menuItem23.Click

Dim item As MenuItem = sender

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(sender As Object, e As System.EventArgs) Handles menuItem20.Click, menuItem21.Click, menuItem22.Click

Dim item As MenuItem = sender

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(sender As Object, e As System.EventArgs) Handles menuItem17.Click, menuItem18.Click, menuItem19.Click

Dim item As MenuItem = sender

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
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.

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