Role of DockStyle property when adding controls
I recently ran into scenario where I had to rearrange some controls in an existing form. In a form, I had a splitter, topGrid and bottomGrid. The DockStyle for topGrid was set to Top, for splitter, it was set to top and for bottomGrid it was set to Fill. I had to change the dockstyle of topGrid to Fill and bottomGrid to bottom. As soon as I changed it, the topGrid would span the whole form and thus, I could not see a part of it. I had no idea why this was happening. I tried different things like updating the values in the code (and not in design mode). I even switched the grid positions to see if something was wrong with the layout itself but the bottomGrid always worked fine and seemed to stick to it's position.
I almost gave up and was on the verge of putting them in separate panels when I realized that this weird behavior is being caused by the order the controls were added to the form. The control that is added last takes the topmost priority. And when I looked in the generated code, sure enough, the topGrid was the last one added and hence whenever I set it's DockStyle to Fill, it would occupy the whole grid and then the other controls would be added on top of it.
So I went into the generated code and manually rearranged the order in which controls are added and it worked exactly as I wanted.
You can find more info at:
http://www.bluevisionsoftware.com/WebSite/TipsAndTricksDetails.aspx?Name=DockStyle
http://msdn2.microsoft.com/en-us/library/system.windows.forms.dockstyle.aspx
Happy Coding!