Panel w/ border help

N

Nathan Laff

I've got a custom Panel that draws a colored border for me. Works great,
however a new problem I've run into is this.

I have the custom panel, then I want to put another panel (just a
Windows.Forms.Panel) inside it, and dock it to the top. When i do this, the
docked panel paints over the border of the custom panel where it is docked,
so some of the left and right (the height of the child panel) and all of the
top.

How can I force my custom panel to draw on top of the child panels? Or is
there another solution?

Please help, I've been spinning my wheels on this for a while now!

Thanks!
 
N

Nathan Laff

Oh yeah, I should mention I tried overriding DisplayRectangle and bringing
it in a few pixels, but that doesn't seem to do anything.
 
P

Paul E Collins

Nathan Laff said:
I've got a custom Panel that draws a colored border for me. Works
great, however a new problem I've run into is this.
I have the custom panel, then I want to put another panel (just a
Windows.Forms.Panel) inside it, and dock it to the top. When i do
this, the docked panel paints over the border of the custom panel
where it is docked, so some of the left and right (the height of the
child panel) and all of the top.
How can I force my custom panel to draw on top of the child panels?
Or is there another solution?

Could you set the panel's Padding so that docked child items avoid its
outer edge?

Eq.
 
M

Morten Wennevik [C# MVP]

Hi Nathan,

As Paul said, if you set the custom panel's Padding you should be able to prevent docking to cover the borders. Furthermore, overriding Paddingin the custom panel will help you prevent the user from manually covering the borders.

private const minpadding = 2;
public new Padding Padding
{
get { return base.Padding; }
set
{
int l = value.Left < minpadding ? minpadding : value.Left;
int r = value.Right < minpadding ? minpadding : value.Right;
int t = value.Top < minpadding ? minpadding : value.Top;
int b = value.Bottom < minpadding ? minpadding : value.Bottom;

base.Padding = new Padding(l, t, r, b);
}
}
 
N

Nathan Laff

Thanks Paul and Morten!

I figured this out a few minutes after i originally posted.

Appreciate it! Thank you!


Hi Nathan,

As Paul said, if you set the custom panel's Padding you should be able to
prevent docking to cover the borders. Furthermore, overriding Padding in
the custom panel will help you prevent the user from manually covering the
borders.

private const minpadding = 2;
public new Padding Padding
{
get { return base.Padding; }
set
{
int l = value.Left < minpadding ? minpadding : value.Left;
int r = value.Right < minpadding ? minpadding : value.Right;
int t = value.Top < minpadding ? minpadding : value.Top;
int b = value.Bottom < minpadding ? minpadding : value.Bottom;

base.Padding = new Padding(l, t, r, b);
}
}
 

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