4

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.

Matthew Vines
  • 27,253
  • 7
  • 76
  • 97
  • 1
    Possible duplicate of [Centering controls within a form in .NET (Winforms)?](http://stackoverflow.com/questions/491399/centering-controls-within-a-form-in-net-winforms) – Jim Fell May 19 '16 at 18:49

2 Answers2

13

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

Matthew Vines
  • 27,253
  • 7
  • 76
  • 97
1

Look at the TableLayoutPanel control and use it in conjunction with the docking and anchor properties. You should be able to control the layout fairly precisely that way.

Chris Dunaway
  • 10,974
  • 4
  • 36
  • 48
  • Of course. I've been out of Winforms programming for a bit and I missed this one in the docs. Spoiled by css I guess, I didn't look hard enough. Thanks. – Matthew Vines Jun 02 '09 at 22:28