Windows Develop Bookmark and Share   
 index > Windows Forms General > Docking Controls on Forms
 

Docking Controls on Forms

I have a form on which I would like a Left docked OutlookBar and another dynamica control to fill the rest of the form area.  I have used the DockStyle.Left for the OLB and DockStyle.Fill for the control, but the control paints itself "under" the OLB as soon as it is displayed.  

The dynamic controls are created and loaded using Reflection, although I wouldn't think that would matter.  I have also tried setting the OLB DockStyle.Left and the dynamic control DockStyle.Left, but as soon as it is displayed, the dynamic control becomes the left-most control instead of the OLB which was left-most in design time.

If I set the DockStyle.Right for the dynamic control, it will not fill the form area and there will be a large unused area on the form.

Anyone have any ideas other than writing resize code on the form?


Thanks
MigrationUser 1  Friday, February 14, 2003 2:34 PM
Let's see if I'm understanding you here or not, but I think what you want to do is setup two panels (one for the left region and one for the right) and put one control in each, then set the DockStyle to Fill and you should be good.  DockStyle is based off of the Parent Container Control.  If this isn't what you're looking for, I probably didn't understand your question, so if that's the case feel free to re-explain it.
MigrationUser 1  Friday, February 14, 2003 7:33 PM
So I believe the issue may be what order you've added your controls to the form's control collection.

The docking mechanism for Windows forms goes from Controls.Count -1 to 0 and calculates the remaining space for each control.

I imagine what's happening is you're doing something like:

this.Controls.Add(MyOutlookBarControl);
this.Controls.Add(MyDynamicallyCreatedControl);

The order in the control collection is something called "Z-order" - in other words stuff at the end of the collection gets stuffed in the background, stuff at the front will get placed on top.  (Think three dimensional axis.)

Since MyDynamicallyCreatedControl is now at the end of the control collection - it will be laid out first - and since nothing else has been laid out - it will fill up the entire form.  Then it gets to the MyOutlookBarControl and places it on top of MyDynamicallyCreatedControl, because there's basically no where else reasonable for it to go.

To make a long story short - you can make the MyDynamicallyCreatedControl move forwards in Z-order by calling:

MyDynamicallyCreatedControl.BringToFront();  

This will change it's positioning in the Form's Control Collection - it will now get laid out last - which will fill up the remaining space. 

Hope this is what you were asking/helps you out.

Jessica
MigrationUser 1  Tuesday, February 18, 2003 3:06 AM

You can use google to search for other answers

Custom Search

More Threads

• Changing font style of the selected row in DataGrid at runtime
• Disable show pictures under WebBrowser Control
• About Threading
• call WebClient.DownloadFile() from UNC path
• Stop validating when click Cancel button
• the form appears in the task bar
• Load TreeView from database
• IS it possible to load Word into a VB.net App?
• Obtain currently used font in the application.
• Tooltip in a Listview is blinking