Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dock to the top and the left

With An anchor I can write the following line:

myControl.Anchor = (AnchorStyles.Top | AnchorStyles.Left);

And it will anchor myControl to the left and the top.

Why can't I do the following:

myControl.Dock = (DockStyle.Top | DockStyle.Left);

I can write the above line, but all it does is set the DockStyle to left.

Any thoughts/reasons for this?

like image 887
AidanO Avatar asked Aug 09 '10 13:08

AidanO


3 Answers

The reason you cannot do this is because setting a DockStyle basically docks/fills the entirity of the specified edge.

For example, DockStyle.Left means that the height of the item being docked will always be the height of the container and the the X,Y location will always be 0, 0.

DockStyle.Top means that the width of the item will always be the width of the container and the location will always be 0,0.

Setting DockStyle.Top and DockStyle.Left would essentially give you DockStyle.Fill. I.e. the same width and height as the container.

like image 181
djdd87 Avatar answered Sep 23 '22 19:09

djdd87


A Dock is a pre-determined anchor set, whereas an Anchor is a custom dock configuration.

DockStyle.Top is the same as Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right) except that an anchor can sit at any initial position and a dock will move to the far edge.

like image 4
Codesleuth Avatar answered Sep 21 '22 19:09

Codesleuth


The DockStyle can only be set to one value, as opposed to the Anchor that can be set to many.

That is why there is the Anchor property so that you can adjust how the control reacts to the form resizing more specifically.

like image 2
Iain Ward Avatar answered Sep 24 '22 19:09

Iain Ward