Docking and anchoring

Can someone help me out? I have a number of controls on my windowes form and I want to make sure that controls and text enlarge and shrink when the screen resolution changes
LVL 35
Who is Participating?
Jacques Bourgeois (James Burger)PresidentCommented:
No need for a TableLayoutPanel or other stuff like that for what you need to do, since the controls are layered on top of each other. The Anchor property is sufficient.

Anchor fix the margins around a control. You simply (however it is not always that simple :-)) set the margins that you want to stay fixed.

Let's start from the bottom. You probably to not want the buttons to enlarge, simply be sure that they stay at the bottom of the screen. So set their anchor property to Bottom. That fixes the margin between the bottom of the buttons and the bottom of the form. So, when you enlarge or reduce the form vertically, they stick to the same distance from the bottom. They will always be at the bottom of the form. Since you did not set lateral anchors, they will simply keep a relative position if the form is enlarged.

The RichTextBox controls, you might want to leave at the same heigth, but enlarge or reduce their width if the width of the form changes. Set their Right and Left anchors. Since the margin right and left is then fixed, they will enlarge horizontally. If you want them to stick to their same position relative to the buttons, also set their bottom anchor. So they will always keep the same distance from the bottom of the screen, going down with its lower border if the height of the screen gets bigger.

The PictureBox, you might want to enlarge in all directions. Set its Anchor property all around.

The idea is that, either horizontally, either vertically:

If you set both anchors, the control enlarge in that direction (horizontally or vertically).

If you set only one anchor, the control stays at the same position relative to the anchor you have set, and thus "follow" that border as the form resizes.

If set no anchor, the control keeps a relative position in that direction. So, if the control is 1/3 of the way up in the original form, but you did not set the Top and Bottom anchor, it will always stay 1/3 of the way up, no matter how big or small is the form.

Post a screenshot of the original form, and a screenshot of how you would like it to show when enlarged. I might be better able to help you to the proper settings if those I gave you here do not suit what you want to achieve.
Naman GoelSoftware engineer 1Commented:
use layout control, table layout panels/flow layout panels based on your ui design dock them on parent form/control then drop your control accordingly and dock them on container control
YZlatAuthor Commented:
let me clarify, you mean use TableLayoutPanel?
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Naman GoelSoftware engineer 1Commented:
YZlatAuthor Commented:
Can you be more specific?

I have a picture box, two richtextbox controls, and two buttons. I need a picturer box up top, then two richtextbox controls one under the other and finally a row with two buttons
YZlatAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.