Library tutorials & articles

Planning Form Layout in VB.NET

The problem

Let the labels remain anchored to their default values Top, Left. Which means they will maintain a constant distance from the top and left edges of the form/panel.

Do the same thing for the blue panel. The red panel needs to behave a little differently. The textbox (set Multiline property of the textbox to True) needs to expand both horizontally as well as vertically when the form expands. So set the anchor property of the textbox to all four direction Top, Bottom, Left, and Right.

Anchor the label 'Remarks:' only to left, so that it sticks to the left edge and also repositions itself vertically at proportional distances from the top and bottom edges of the panel.

Next the two buttons 'Save' and 'Cancel' needs to be anchored to the bottom-right corner as shown below.

Now go ahead now, save your work and hit F5. You see that the controls are getting resized along with the form. Bingo!!! , You did all this without writing a single line of code. Now see what happens when you maximize the form… Hey! Wait a minute; this is not exactly what we wanted….

What exactly is happening here is that, the blue and the green panels are not resizing horizontally in equal proportion. Since the green panel is set to dock to the left and the blue panel is set to fill up the remaining horizontal area, we see that this is exactly what is happening. The same thing is happening to the red panel as well, it is docking itself to the bottom and the other two panels are taking up the rest of the space vertically.

Comments

  1. 01 Sep 2008 at 12:58
    It is difficult to design fairly complicated forms by simply using anchors and docks. .Net provides two layout manager Flow layout panel and Table Layout Panel. However you need to use a good layout manager for professional form designing, e.g. SmartLayouts .
  2. 28 Oct 2003 at 05:21

    I would use 4 panels in the following way:
    1) one up (this is the extra panel that is not in your example). Set the Dock property to this one to Top and set the Height to whatever you want.
    2) The Green panel will be inside the panel one. Set the Dock property to Left and set the Width to whatever you want
    3) The Bleu panel also inside the panel one. Set the Dock property to Fill.
    4) The fourth panel (the Red one) comes bottom (as child of the form) with Dock set to Fill. (this is also a difference to your example)


    The rest of the things are the same.
    What we have accomplished with the fourth panel ? The fact that the Height of the Blue/Green panels is fixed to the height of the Panel One, so no coding is necessary to keep the height fix.


    The only problem left is that the Width of the Green panel is fixed and when the form is made wider it does not resize. So the only code necesary is to make the
    Green panel wider according with the width of the form.


    Best regards,
    Dan

  3. 15 Dec 2002 at 07:55

    good work - and helpful!

  4. 07 Mar 2002 at 23:58


    Good one ! Keep it up ...

  5. 07 Mar 2002 at 03:05

    This is very very very nice


    [6]keep it up[/6]


    good work


  6. 01 Jan 1999 at 00:00

    This thread is for discussions of Planning Form Layout in VB.NET.

Leave a comment

Sign in or Join us (it's free).

Benny K. Mathew Benny Mathew is the Founder, CEO of Seamless Integration Solutions Pvt. Ltd. He has 10+ years of formal experience in the IT industry and has provided services to many of the well known multi-natio...
AddThis

Related podcasts

  • xpert to Expert: Inside Concurrent Basic (CB)

    "Concurrent Basic extends Visual Basic with stylish asynchronous concurrency constructs derived from the join calculus. Our design advances earlier MSRC work on Polyphonic C#, Comega and the Joins Library. Unlike its C# based predecessors, CB adopts a simple event-like syntax familiar to VB progr...

We'd love to hear what you think! Submit ideas or give us feedback