Results 1 to 6 of 6

Thread: Anchor & Dock For Automatic Resizing

  1. #1
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,860

    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   
    Last edited by jmcilhinney; Oct 18th, 2010 at 12:21 AM.

  2. #2
    PowerPoster formlesstree4's Avatar
    Join Date
    Jun 08
    Location
    On the Internet
    Posts
    2,870

    Re: Anchor & Dock For Automatic Resizing

    Great tutorial for newbies who are learning about anchoring controls. Good job JMC.

  3. #3
    Hyperactive Member
    Join Date
    Dec 09
    Posts
    453

    Re: Anchor & Dock For Automatic Resizing

    Hi john. I stumbled upon this while searching the forums. Would you say it's out side the scope of this thread to ask about anchoring with inside a user control? To make it clearer if i had a mainform that housed a user control. When mainform re-sized it re-sized the user control and controls? The user control does not resize when Mainform does.

    Should i make my own thread
    Last edited by kayleigh; Jan 10th, 2012 at 01:53 PM.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,860

    Re: Anchor & Dock For Automatic Resizing

    Quote Originally Posted by kayleigh View Post
    Hi john. I stumbled upon this while searching the forums. Would you say it's out side the scope of this thread to ask about anchoring with inside a user control? To make it clearer if i had a mainform that housed a user control. When mainform re-sized it re-sized the user control and controls? The user control does not resize when Mainform does.

    Should i make my own thread
    Anchoring & docking is relative to a controls immediate parent. Any child controls in a UserControl will resize based on the UserControl and a UserControl on a form will resize based on the form. A UserControl is just like any other control. If you have set the Anchor and/or Dock properties of a UserControl on your form and it doesn't resize with the form then something is broken in your project or your system because a UserControl is a control and it behaves like any other control.

  5. #5
    Member
    Join Date
    Jun 10
    Posts
    40

    Re: Anchor & Dock For Automatic Resizing

    Is there anything similar to Anchor/Dock in VB6?

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,860

    Re: Anchor & Dock For Automatic Resizing

    Quote Originally Posted by IHappenToBe View Post
    Is there anything similar to Anchor/Dock in VB6?
    The VB6 forum would be the logical place to ask that question. I've never used VB6 and I'm glad of it.

Posting Permissions

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