Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to keep objects in place when window is resized in C#

How can I keep the objects of my window (buttons, labels, etc) in center when the window is resized?

Currently, I have 3 buttons in a Windows Form. When I maximize the window, the buttons stay at the top left section of the window. I want them to be in the center as they were when the window was not maximized.

Any help?

like image 425
PHP Developer Avatar asked Oct 19 '12 11:10

PHP Developer


People also ask

How do you resize a window and keep it that size?

Move or resize a window using only the keyboard. Press Alt + F7 to move a window or Alt + F8 to resize. Use the arrow keys to move or resize, then press Enter to finish, or press Esc to return to the original position and size. Maximize a window by dragging it to the top of the screen.

How do I stop QT resizing?

Use setFixedSize(). It should disable resizing.

Is it possible to resize a control within the form design window?

You can resize individual controls, and you can resize multiple controls of the same or different kind, such as Button and GroupBox controls.


2 Answers

You should set the Anchor properties of the object to none,

This will keep it in the middle.

like image 50
SirDuckduck Avatar answered Sep 28 '22 11:09

SirDuckduck


Set the Anchor property of your controls correctly. By default your control is anchored to Top,Left. If you clear this property (anchor to nothing, essentially), your button will remain centered.

(It may seem like you want to anchor to all four sides, but in reality what this will do is resize your button to fill the form!)

like image 37
Dan Puzey Avatar answered Sep 28 '22 10:09

Dan Puzey