Wednesday, February 9, 2011

How do I resize my panels when resizing the main form in a winforms application?

If the user of my winforms application resizes the main form, I want the 2 panels to stretch out also, along with the child controls.

How can I achieve this?

  • Play around with the Dock and Anchor properties of your panels.

  • You can use the TableLayoutPanel and set column width at x% each this way you will have the screen split in 2. The TableLayoutPanel must be Dock to fill all the form or Anchor.

    The TableLayoutPanel can contain other panel. OR you can use simply your panel and use Anchor (click the panel and go in the Properties panel of VS).

    From Daok
  • If the user of my winforms application resizes the main form, I want the 2 panels to stretch out also, along with the child controls.

    You're the ideal use case for TableLayoutPanel (MSDN). If you were only scaling the panels, Dock and Anchor would be appropriate. But since you want your controls to scale well, you're pretty much in an AutoLayout world, and likely the TableLayoutPanel. (I'm a huge fan of this, by the way, although overuse can have a negative performance impact on laying out your controls.)

    Some helpful links on using it to configure your layout to scale:

    MusiGenesis : Argh. I write software for Windows Mobile devices, and once again I just had the experience of learning about a cool .NET feature that isn't in the Compact Framework.
    John Rudy : For future visitors of this answer: I just noticed a link to my blog in this answer, and have now removed it, as I shut the blog down many months ago. I apologize for the inconvenience.
    From John Rudy
  • See following:
    http://urenjoy.blogspot.com/2008/11/make-resolution-independent-windows-app.html

    From Brij

0 comments:

Post a Comment