Stop buttons stretching on resize when anchored left and right

Posted on 2009-05-24
Medium Priority
Last Modified: 2013-12-17
I have a windows form with a whole bunch of buttons and labels all laid out nice and pretty like. I want them to stay more or less in the middle when the window is resized. Moving them horizontally is fine with bigger gaps between them. Or leave them exactly as I designed them in the center.

I have set the "Anchor" to "Bottom, Left, Right" and "Autosize" to "False". However, the labels don't move and the buttons stretch. Is there a way to stop this from happening?

I just got the labels to move by setting the "TextAlign" to "TopCenter". However, when resized enough the labels start disappearing by going under another label. So I guess the labels are stretching as well.
Question by:dij8
LVL 15

Expert Comment

ID: 24463191
I don't think you can do that with anchoring - you could try using a docked tableLayoutPanel - give it 3 columns and put your buttons in the center column and give all columns percentage widths rather than absolute widths.
LVL 86

Accepted Solution

Mike Tomlinson earned 500 total points
ID: 24463199
"Or leave them exactly as I designed them in the center."

If you want them to NOT resize and just stay centered then turn OFF all of the Anchor/Dock settings and they will stay just as you designed them in the middle of the form.
LVL 15

Expert Comment

ID: 24463351
It is streching because you have it anchored with respect to bottom left and bottom right.

If you want it to stay relative to one or the other then turn off either left or right, and it will stay relative to the one left on. By default controls are anchored to top left. You can't anchor a control to the centre of the form.

If yoou dont want users to resize the form then you can stop thyem from doing so using the properties of the form
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24463386

    "You can't anchor a control to the centre of the form."

Sure ya can bud.  =)

See my comments above.  Turn OFF all of the Anchor properties and see what happens....
LVL 10

Author Closing Comment

ID: 31584864
Here I was thinking I had to be clever to achieve this. No anchoring is indeed the answer. :)

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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.

Join & Write a Comment

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…
Watch the video to know the simple way to remove or recover or reset lost or forgotten passwords of Outlook PST file. With Kernel Outlook Password Recovery tool such operation is very easy to perform. It is a freeware with limitation to use with 500…

624 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