How to dock a child control to bottom right of the parent control?
Solution 1
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.
Solution 2
Use AnchorStyles:
yourComponent.Anchor = ((System.Windows.Forms.AnchorStyles)
((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
Nick
Updated on June 09, 2022Comments
-
Nick almost 2 years
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 ???
-
Nick almost 12 yearsThats exactly what i want . i need the child control to fit within the height and width of the parent form ... if i set the anchorstyle to bottom right , i m unable to see the control, i m guessing its going beyond the bounds of the parent control....
-
JotaBe almost 12 yearsPlease define it more exactly. Do you want it on the bottom, taking all the width or on the right taking all the height? if you help me to understand it I'll improve my answer.
-
Nick almost 12 yearsOkie.. thanks for the info, let me dock the control bottom and align the label field to right...
-
General Grey almost 12 yearsI believe JotaBe is Correct, you need to set your anchor to Bottom right and locate it exactly where you want it to stay, when you resize your Form it will stay relative to the bottom right corner
-
Nick almost 12 yearsi want it to be on the right , taking all the width of the parent control but should be able to define height...
-
General Grey almost 12 yearswell then dock to bottom, that will take all the width of the parent control be able to define the height, What is the Control you are adding though, you may have to turn AutoSize=false
-
General Grey almost 12 years@JotaBE His control is a Label, dock to bottom align to right Autosize false, I think it is a label anyway, so confusing when people don't give you all the information you need