Pregunta

How do i dock a child control at a bottom right position when compared to the parent control?

I can see that the dockstyle enum has values for None,Top,Bottom,Right,Left and Fill ...

How can i set for Bottom right ???

¿Fue útil?

Solución

perhaps you don't want to dock it bottom-right. Docking changes the position of the control, but also the size to fit in th height or width of the form.

If you want to keep it down and on the right, anchor it.Remove left and top anchors and add bottom and right anchors. Your control will keep there!

** EDIT ** According to OP comment, it must be on the bottom and take all width and have fixed height. then you must take this steps:

To keep it tidy, you need at least 2 controls:

  • The one that it's on the bottom: dock it to the bottom and set its height.
  • Other one that use docking style of Fill. This makes it take all the space not occupied by the bottom control.

If you have problems setting it up, use the Layout Window (I hope that's the name in English. My VS is localized) to move them around until it works. Sometimes docking it's a bit nasty and the only way to make it work the way you like is changing the order nad nesting of controls using this layout window.

Otros consejos

Use AnchorStyles:

yourComponent.Anchor = ((System.Windows.Forms.AnchorStyles)
                       ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));

From MSDN documentation for Control.Dock:

A control can be docked to one edge of its parent container or can be docked to all edges and fill the parent container.

So you cannot dock to two edges - I'm actually not sure what you mean by this.

If you want to keep a control in the bottom right of the screen you might be thinking of the Anchor property, which does let you set multiple edges to anchor the control to.

try setting the Dock to Bottom, Depending on your control you may have to turn autosize off, a label for instance

To "dock" in the bottom right, you need to

  1. Dock ControlA on the Right side of the parent, ControlB
  2. Set the Top Padding of ControlA to ControlA.Padding = new Padding(0, ControlB.Height - nTopPadding, 0, 0);

nTopPadding can be whatever you need it to be. For TextBoxes, Labels, and the like, ControlA.Font.Height works the best.

This also works when AutoSize = true. You'll only need to update the padding as needed.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top