Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I center controls without resizing them? (.net Winforms)

I have a fairly simple user control that represents a basic login control. So it has a couple labels, text boxes, and a button. I would like this user control to fill its container, so I have set its dock mode to fill. So far easy enough.

Now, I would like all the controls in my user control to be centered based on whatever size my user control is when rendered. I can't think of a anchor / dock combination that will do the trick.

The user control has a ReSize event. So I know I can calculate and move the controls based on my User control's size during that event. But I was hoping this issue was common enough to be handled through the designer if I desired.

like image 406
Matthew Vines Avatar asked Dec 09 '22 20:12

Matthew Vines


1 Answers

It is actually all pretty simple. You just have to turn off all anchor properties, and set dock to none.

like image 192
Matthew Vines Avatar answered Dec 12 '22 10:12

Matthew Vines