D
David Veeneman
Is there a simple way to change a UserControl border color?
I'm creating a UserControl that will have a border, using the
UserControl.BorderStyle property. The standard border is black; I'd like to
change the color to something a little more appealing. I've tried overriding
OnPaint, like this:
public partial class MyControl : UserControl
{
public MyControl()
{
this.SetStyle(ControlStyles.UserPaint, true);
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (this.BorderStyle == BorderStyle.FixedSingle)
{
int borderWidth = 1;
Color borderColor = SystemColors.ControlDark;
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle,
borderColor, borderWidth, ButtonBorderStyle.Solid,
borderColor, borderWidth, ButtonBorderStyle.Solid,
borderColor, borderWidth, ButtonBorderStyle.Solid,
borderColor, borderWidth, ButtonBorderStyle.Solid);
}
}
}
That doesn't work, because it leaves the black border. Plus, UserPaint
setting apparently drops all control painting in my lap, when all I want to
do is change the border color.
Is there a P/Invoke or a Windows message I can use to change the border
color? Thanks.
I'm creating a UserControl that will have a border, using the
UserControl.BorderStyle property. The standard border is black; I'd like to
change the color to something a little more appealing. I've tried overriding
OnPaint, like this:
public partial class MyControl : UserControl
{
public MyControl()
{
this.SetStyle(ControlStyles.UserPaint, true);
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (this.BorderStyle == BorderStyle.FixedSingle)
{
int borderWidth = 1;
Color borderColor = SystemColors.ControlDark;
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle,
borderColor, borderWidth, ButtonBorderStyle.Solid,
borderColor, borderWidth, ButtonBorderStyle.Solid,
borderColor, borderWidth, ButtonBorderStyle.Solid,
borderColor, borderWidth, ButtonBorderStyle.Solid);
}
}
}
That doesn't work, because it leaves the black border. Plus, UserPaint
setting apparently drops all control painting in my lap, when all I want to
do is change the border color.
Is there a P/Invoke or a Windows message I can use to change the border
color? Thanks.