Jump to content

VS2010: How to dock to centre

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
strider96

strider96

    Newbie

  • Members
  • Pip
  • 7 posts
Hi,
I have problem with VS 2010,
There is no way to dock to the centre...

The middle one is fill (covers the whole form)

Please Help!
:confused: :confused: :confused: :confused:

#2
marceloxlo

marceloxlo

    Newbie

  • Members
  • Pip
  • 8 posts
you got that in other forum :D

If you want the control to stay in the middle of the form then it's not really docking. A ship doesn't dock in the middle of the ocean. Docking implies being adjacent to something. In the case of controls, they are docked to one or all sides of their container.

If you want a control to stay in the middle of a form and not get resized then you pretty much have two choices:

1. Add a TableLayoutPanel with three rows and three columns. Make the middle row and column auto-size so they will fit your control exactly, then make the other rows and columns 50% each. As the form resizes the TLP will expand and contract the outer rows and columns equally while keeping the middle row and column auto-sized to your control.

2. Handle the SizeChanged event of your form and manually calculate the new Location for the control. It's a pretty simple calculation based on the Height and Width of the form and the control.