Docking and anchoring

Posted on 2011-10-03
Last Modified: 2013-11-26
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
Question by:YZlat
    LVL 13

    Assisted Solution

    by:Naman Goel
    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
    LVL 35

    Author Comment

    let me clarify, you mean use TableLayoutPanel?
    LVL 13

    Expert Comment

    by:Naman Goel
    LVL 35

    Author Comment

    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
    LVL 40

    Accepted Solution

    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.
    LVL 35

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from ( Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now