Live Chat Icon For mobile
Live Chat Icon

How can I change the Border color of my control

Platform: WinForms| Category: Controls

Override the OnPaint. Here is some code for a derived Button.

[C#]
	public class MyButton : Button
	{
		protected override void OnPaint(PaintEventArgs e)
		{
			base.OnPaint(e);
			int borderWidth = 1;
			Color borderColor = Color.Blue; 
			ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, borderColor,
					borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth,
					ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid,
					borderColor, borderWidth, ButtonBorderStyle.Solid);
		}
	}

[VB.NET]
	Public Class MyButton
		Inherits Button
   
		Protected Overrides Sub OnPaint(e As PaintEventArgs)
			MyBase.OnPaint(e)
			Dim borderWidth As Integer = 1
			Dim borderColor As Color = Color.Blue
			ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, borderColor, borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid)
		End Sub ’OnPaint
	End Class ’MyButton

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.