Panel Resize Problem

  • Thread starter Thread starter JS
  • Start date Start date
J

JS

Hey all,

I have three panels that take up the full width of the form minus the
splitter docked to the left and they are all anchored.

Panel1 (top panel) has a button on it to allow the user to change the height
depending on the current height.


private void BtnExpand_Click(object sender, System.EventArgs e)
{
if(this.Panel1.Height == 220)
{
this.Panel1.Height = 35;
}
else
{
this.Panel1.Height = 220;
}
}


This code works works exactly like I want it to. The problem I'm having is,
getting panel2 (middle panel) to keep it's anchor with panel1. Another
problem with this is getting Panel3 (bottom panel) to resize and stay
anchored with panel2.

Summary:
If Panel1 is resized, move Panel2 just below Panel1 and resize Panel3 to
fit in the remaining area of the form.

I thought about docking Panel3 to the bottom for the resize, but that screws
up my splitter.

Any help would greatly be appreciated.

Thanks,

- JS -
 
I'm not exactly sure what you are trying to do, but I
have found a similar problem before. It may not help b/c
it may not be the same problem.
Panels will only respond to other panels (or anything)
that are created BEFORE it. Meaning if you create 2
panels, Panel1 first, then Panel2, Panel1 will not resize
automatically when Panel2 moves, because (as far as I can
tell) it didn't know it existed at the time of its
creation. I don't know if your panels were created in
the order they are numbered. Did you delete the original
Panel1 to start over with a fresh one? If you dock
panel3 to the bottom of the form, I don't see a problem
with that, as long as you also anchor it to panel2 above
it (again, panel2 must be older). It sounds like you
want panel2 to stay the same size and just move in the
middle, or do you want it to shrink and panel3 to stay
the same size? If the one on the bottom is supposed to
stay the same size, make it the oldest, and the other 2
can build off of it and the top of the form (which is
obviously older). Then you can have a splitter in
between the top 2 (must be older than the 2 panels) or
whatever you want.
I don't know why this is, or if it has been addressed in
v1.1 of the .NET Framework, but it caused me much torment
before expiramentation led me to my current view on
docking and anchoring. Good luck.

Stephen
 
I suspect you are encountering the fact that docking is totally dependent
upon the z-order (aka the index of a control in the form's Controls[] array)
of your Panels, among other things (Panels don't "anchor" to one another)..

And, unfortunately, Microsoft's documentation regarding docking "is a little
light" (From the Help entry for Control.Dock property: "Controls are docked
in order of their z-order.") An alternative explanation (one that is
hopefully more useful) would be that controls occurring lower in the
Controls[] array are "closer to the edge they are docked to" than controls
that are Form.Add()ed afterward.

The following arrangement will give you the "Resize panel 1, Panel 2 will
stay the same size, Panel 3 will change size accordingly" behavior.

[Panel 1 (.Dock = DockStyle.Top)]
[Panel 2 (.Dock = DockStyle.Top)]
[Panel 3 (Dock = DockStyle.Fill)]

It isn't clear what you are trying to do with the splitter, since you say it
is docked .Left. - having a splitter for changing the height of Panels 1-3
would normally have .Dock = Top or .Dock=Bottom.

Life gets REALLY interesting in Dock-land when you start having multiple
controls docked to .Top and .Bottom - "Yes, boys and girls, watch with
amazement as your panels slide one-under-another as the form is resized,
appearing and disappearing before your very eyes".


--
Regards,

Jim Allison
(e-mail address removed)
(de-mung by removing '.1')
 
Back
Top