Docking controls on Windows Forms

  • Thread starter Thread starter Leon Jollans
  • Start date Start date
L

Leon Jollans

I've been having loads of problems with this. Coming from Java I never had
this problem with the LayoutManagers, but it keeps happening in the VS.NET
designer, and I don't know where the issue's coming from.

Say I have a form and place two controls on it - in this instance a
CrystalReportViewer and a Panel. I set the Panel to Dock Right and the
CrystalReportViewer to Dock Fill. Now according to both my Java AWT and
Swing experience the CrystalViewer should Fill the *remaining* space, but it
doesn't, it acts as if the Panel wasn't there at all and fills the entire
form, clipped by the Right docked Panel rather than resizing to meet its
edge.

This is stopping me using splitters correctly too, since DockStyle.Fill
simply refuses to adjust to the remaining space. Other people can do it, and
I've seen tutorials that demonstrate the correct behaviour using the same
method as I am, so what am I doing wrong??

TIA

Leon
 
Hi,

Leon said:
I've been having loads of problems with this. Coming from Java I
never had this problem with the LayoutManagers, but it keeps
happening in the VS.NET designer, and I don't know where the issue's
coming from.

Coming from Java you might benefit from this:

http://tinyurl.com/m8xj

It's not a complete system, but it's a step in the right direction. I've
seen similar work on implementing layout managers in .NET on other sites
too. Try a search if you want to go that way.
This is stopping me using splitters correctly too, since
DockStyle.Fill simply refuses to adjust to the remaining space. Other
people can do it, and I've seen tutorials that demonstrate the
correct behaviour using the same method as I am, so what am I doing
wrong??

As I understand matters, you are having z-order problems. Either add
controls in a different order, or use the bringtofront and sendtoback
(probably not quite the right names) to change the order. I think you can
also do SetChildIndex on the parents Controls container.

Hope that helps.

-- Pete
 
I believe the correct way is like this:

1) add a control and dock it to the right
2) add a splitter control and dock it to the right too
3) add a second control and dock it fill.

Then you should be able to grab the splitter and actually
change the size of the split...
 
The order in which you create controls is very important in my experience.
Whatever is going to be set to Fill must be created on the form last or else
it doesn't recognize the other controls existence at the time of its
creation. Remember that when you draw controls on a form and set their
properties it just places the code for that in the InitializeComponents()
routine. So if it hits the code for the CrystalViewer before the Panel is
created and placed, it will fill the entire form and the Panel will just go
on top or under it. Let me know if that doesn't help, but it did in my
experience.

Stephen
 
It's pretty easy when you get used to it. The Z order of the control
determines the docking behavior. When the situation you describe occurs,
right click on the offending control and select "Bring to Front" from the
context menu (or use the Format/Order/Bring to Front menu.)

Tom
 
That link's really useful. thanks!


Pete said:
Hi,



Coming from Java you might benefit from this:

http://tinyurl.com/m8xj

It's not a complete system, but it's a step in the right direction. I've
seen similar work on implementing layout managers in .NET on other sites
too. Try a search if you want to go that way.


As I understand matters, you are having z-order problems. Either add
controls in a different order, or use the bringtofront and sendtoback
(probably not quite the right names) to change the order. I think you can
also do SetChildIndex on the parents Controls container.

Hope that helps.

-- Pete
 
Back
Top