Results 1 to 10 of 10

Thread: Anchor & Dock For Automatic Resizing

Threaded View

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Anchor & Dock For Automatic Resizing

    A lot of people ask how to get their controls to resize when they resize their form. The answer is to use the Anchor and/or Dock properties. For complex layouts, you might also need to use a TableLayoutPanel and/or FlowLayoutPanel. Here's a quick demo. Attached are screen shots of a form in the designer at the default 300x300 and then resized to 640x480. Note that the layout of the controls is maintained. The values of the Anchor and Dock properties of each control are listed below.

    Label1.Anchor = Top, Left
    Label1.Dock = None

    TextBox1.Anchor = Top, Left, Right
    TextBox1.Dock = None

    Button1.Anchor = Top, Right
    Button1.Dock = None

    Label2.Anchor = Top, Left
    Label2.Dock = None

    ComboBox1.Anchor = Top, Left, Right
    ComboBox1.Dock = None

    TableLayoutPanel1.Anchor = Top, Bottom, Left, Right
    TableLayoutPanel1.Dock = None

    TextBox2.Anchor = Top, Left
    TextBox2.Dock = Fill

    TextBox3.Anchor = Top, Left
    TextBox3.Dock = Fill

    TextBox4.Anchor = Top, Left
    TextBox4.Dock = Fill

    TextBox5.Anchor = Top, Left
    TextBox5.Dock = Fill

    TextBox6.Anchor = Top, Left
    TextBox6.Dock = Fill

    TextBox7.Anchor = Top, Left
    TextBox7.Dock = Fill

    Button2.Anchor = Bottom, Right
    Button2.Dock = None

    Button3.Anchor = Bottom, Right
    Button3.Dock = None

    In addition, note that the TableLayoutPanel containing the six multi-line TextBoxes is configured to have two columns, each with a width of 50.00%, and three rows, each with a height of 33.33%
    Attached Images Attached Images   

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width