Search code examples
c#visual-studiowinformsanchor

why some elements on my C# form change width or position when I change forms width, even though they do not have an anchor set to left or right?


I have a button that changes its width, it has following properties:

button 1 props

And a whole row of buttons labels textboxes and numericrdopdowns that changes their location as if they areattached to the right edge of the form only, their properties:

row 2 props

What should I change so that these elements stay in place and not change width when I change my form's width?


Solution

  • Judging by the picture you represented.

    You selected Grow only on the button's autosizemode.

    Below are links to the relevant attributes.

    Grow only

    If you don't have any DPI aware changes set, and autosize. Their size will not change.

    In addition, you have set their anchor to the top. This may change their position when the width changes.

    button1. Anchor = AnchorStyles.Top | AnchorStyles.Left;

    You can choose to anchor it in the top left corner.

    Or put these controls in a panel.