I’ve added a custom border to the labels in one of my application forms as follows:
private void ColorMe(PaintEventArgs e)
{
Color myColor = Color.FromArgb(104, 195, 198);
Pen myPen = new Pen(myColor, 1);
e.Graphics.DrawRectangle(myPen,
e.ClipRectangle.Left,
e.ClipRectangle.Top,
e.ClipRectangle.Width - 1,
e.ClipRectangle.Height - 1);
base.OnPaint(e);
}
private void lblDisbs_Paint(object sender, PaintEventArgs e)
{
ColorMe(e);
}
Which works nicely. All I have to do it put ColorMe(e) in the Paint Event of each label.
However I want to use this method on all forms throughout the whole application. I tried putting my ColorMe() method in a class to call it from multiple forms that way, but it does not work, saying that ‘base has no OnPaint event’.
How should I make this method available throughout the whole application?
Create class
LabelWithBorderderive it fromLabel, override theOnPaintmethod.Replace all WinForms labels in your app with your label.