.NET Windows Forms - Can't Change Docking Order

Having trouble adjusting the docking order of your controls in a .net windows forms application? Simply undocking and then redocking the controls in the order you want hardly ever works.

The only way I've found to consistantly get this to work is to undock all of the applicable controls from their container.  This could be all controls on a form or all controls on a given panel (or some other container control).

Then, dock the first control.  For all subsequent controls that need to be redocked, use CTRL-X to temporarily delete them from Visual Studio and then CTRL-C to paste them back in again.  Then, redock that control.  You'll have to do this for each control.  All of the control names and attributes will remain the same.

However, you will need to recreate the event wireups.  For most controls, this is as simple as double clicking the control or going to the events section of the property grid.

After you have done this, close the designer for the form and open the .cs code file.  If you have found that Visual Studio created new event place holders like this:

old

private void mybutton_onclick

new

private void mybutton_onclick_1

Remove the new instance and try to compile your app.  Visual Studio
should fail to compile and give you all the places you need to tweak in the designer.cs file.

What is important to note is that if you attempt to fix the event place holders while the form is still up in design mode, Visual Studio will remove all of the newly created placeholders and you'll be back to square one for recreating your event placeholders.

By Robbe Morris   Popularity  (4153 Views)
Picture
Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.  Robbe also loves to scuba dive and go deep sea fishing in the Florida Keys or off the coast of Daytona Beach. Microsoft MVP