Create two properties: one for BorderColor, and another one for BorderStyle. Have the method use the values from these properties instead of hard-coding the settings. Change the property to change the way the label appears.
public class DashedLabel : Label
{
public DashedLabel()
{
DashStyle = DashStyle.Dash;
BorderColor = Color.Black;
}
public DashStyle DashStyle { get; set; }
public Color BorderColor { get; set; }
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Pen p = new Pen(BorderColor);
p.DashStyle = DashStyle;
Rectangle rect = new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width - 1,
e.ClipRectangle.Height - 1);
e.Graphics.DrawRectangle(p, rect);
}
}
Coding Light - Illuminated Ideas and Algorithms in SoftwareCoding Light Wiki �
LinkedIn �
ForumsBrowser