UserControl Border Color

G

Guest

Hi

I have a simple UserControl hosting a couple of other controls, the
BorderStyle = BorderStyle.FixedSingle. All I want to do is change the border
color of the control.

Anyhow got an example on the best approach to do this. I tried the
following which didn't make any difference:

protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
ControlPaint.dr(e.Graphics,
e.ClipRectangle,
SystemColors.Desktop,
ButtonBorderStyle.Solid);
}

Craig
 
T

Tim Wilson

Try setting the BorderStyle to "None" and then something like this...

protected override void OnPaint(PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.Green,
ButtonBorderStyle.Solid);
base.OnPaint(e);
}
 
G

Guest

Hi Tim

Thanks for the reply, your suggestion worked a treat!

I have a follow-on question. Basically same scenario, but instead of being
a UserControl, I would like to chnage the color of the border of a
SplitContainer control.

Your UserControl suggestion unfortunately doesn't work on a SpiltContainer
control :(

Craig
 
T

Tim Wilson

Because the SplitContainer is a control that is composed of other controls
that are docked within it (obscuring its client area in which you want to
paint), one easy way to achieve the appearance of a custom border is to
place the SplitContainer inside another Panel and then resize the
SplitContainer to be slightly smaller than the Panel. Now set the BackColor
of the Panel to the color that should be used for the border. The last step
would be to set the Anchor property for the SplitContainer to be all four
sides (Top, Bottom, Left, Right) - this will ensure that if the Panel is
resized the SplitContainer will be resized appropriately. So the outer Panel
is being used as a custom border.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top