Multiple panels with 'Fill' docking

  • Thread starter Thread starter Steve McLellan
  • Start date Start date
S

Steve McLellan

Hi,

I'm trying to add panels to a parent panel programatically. I'd like them to
all take up an equal amount of the parent form as it's resized etc. Using
Docking::Fill obviously causes one panel to expand to fill the entire
parent, and I can't get a satisfactory result using Anchor - the leftmost
controls start to take more than their fair share as the parent panel grows
in size.. Can anyone suggest a way of doing this? Some kind of grid system
is what I'm looking for I guess. I could achieve this effect with custom
resizing code but I don't want to have to do that if avoidable.

Thanks in advance,

Steve
 
Steve McLellan said:
Hi,

I'm trying to add panels to a parent panel programatically. I'd like them to
all take up an equal amount of the parent form as it's resized etc. Using
Docking::Fill obviously causes one panel to expand to fill the entire
parent, and I can't get a satisfactory result using Anchor - the leftmost
controls start to take more than their fair share as the parent panel grows
in size.. Can anyone suggest a way of doing this? Some kind of grid system
is what I'm looking for I guess. I could achieve this effect with custom
resizing code but I don't want to have to do that if avoidable.

I think that Resize is the only way.
Nevertheless, it doesn't use much lines of code :

private void resize(object sender, EventArgs e)

{

// I have 4 panels, and I want each of them in a corner, and also to take a
quarter of the screen

// L is Left, R right, T top and B bottom

/*********

* LT * RT *

*********

* LB * RB *

**********/

LTpanel.Location = new Point(0, 0);

LTpanel.Width = myPanel.ClientSize.Width / 2;

LTpanel.Height = myPanel.ClientSize.Height / 2;

LTpanel.Anchor = AnchorStyles.Left | AnchorStyles.Top;

RTpanel.Location = new Point(myPanel.ClientSize.Width / 2, 0);

RTpanel.Width = RTpanel.Parent.ClientSize.Width / 2;

RTpanel.Height = RTpanel.Parent.ClientSize.Height / 2;

RTpanel.Anchor = AnchorStyles.Right | AnchorStyles.Top;

LBpanel.Location = new Point(0, RTpanel.Parent.ClientSize.Height / 2);

LBpanel.Width = LBpanel.Parent.ClientSize.Width / 2;

LBpanel.Height = LBpanel.Parent.ClientSize.Height / 2;

LBpanel.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;

RBpanel.Location = new Point(myPanel.ClientSize.Width / 2,
RTpanel.Parent.ClientSize.Height / 2);

RBpanel.Width = RBpanel.Parent.ClientSize.Width / 2;

RBpanel.Height = RBpanel.Parent.ClientSize.Height / 2;

RBpanel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;

}
 
Hi,

Yeah, but when you've got 'n' panels, it becomes harder. I'm going to have
to write a custom layout event handler I think.

Thanks for the reply,

Steve
 
Steve McLellan said:
Hi,

Yeah, but when you've got 'n' panels, it becomes harder. I'm going to have
to write a custom layout event handler I think.

Perhaps, if you have a list of Panels, you can do a list, and loop

while (elements_in_the_list)
{
LTpanel.Location = new Point(x * myPanel.ClientSize.Width / N, x *
myPanel.ClientSize.Height / N);
LTpanel.Width = myPanel.ClientSize.Width / N;
LTpanel.Height = myPanel.ClientSize.Height / N;
x++;
}

And, if it's not only panels, you will have litte changes to do :o)

Hope that help.
 
Hi,

Yeah, I've done a system like that as a layout handler and it seems to work
fine. Thanks!

Steve
 
Back
Top