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?
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.
Use setFixedSize(). It should disable resizing.
You can resize individual controls, and you can resize multiple controls of the same or different kind, such as Button and GroupBox controls.
You should set the Anchor properties of the object to none,
This will keep it in the middle.
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!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With