Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

2. Windows Forms Controls

2.6 How can I change the Border color of my control?


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