logo

.NET Windows Forms - Can't Change Docking Order

By Robbe Morris
Printer Friendly Version
View My Articles
423 Views
    

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.


Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of EggHeadCafe.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.


Didn't Find The Answer You Were Looking For?

EggHeadCafe has experts online right now that may know the answer to your question.  We pay them a bonus for answering as many questions as they can.  So, why not help them and yourself by becoming a member (free) and ask them your question right now?
Ask Question In Live Forum

If you have an OpenID and do not want to become a member of the EggHeadCafe forum, you can also sign on to Chat Chaos and post your question to our real time Silverlight chat application.
Ask Question In Chat Chaos

Article Discussion: .NET Windows Forms - Can't Change Docking Order
Robbe Morris posted at Thursday, October 12, 2006 3:41 PM
Original Article
 






  $1000 Contest    [)ia6l0 iii - $228  |  Jonathan VH - $161  |  Huggy Bear - $135  |  F Cali - $95  |  egg egg - $94  |  more Advertise  |  Privacy  |   (c) 2010