C # / winforms layout: element with right or bottom anchor disappears under parent container

sometimes when I want a winforms control to be docked as well to the right or bottom of the parent container (usually a UserControl), its borders are expanded beyond the parent's right or bottom border so that some of it is not visible anymore. even if the anchor is set to the right.

This only happens when the application starts. while I'm in the designer everything looks fine.

all I do is set the Anchor property of the Right control, for example.

Is there a way to avoid this?

In this screenshot, you can see the Transition group box expanding as the parents expand to the right.

http://www.deviantsart.com/upload/08ffe2f5e7f4d33044840e68e0619152.png

thanks!

0


a source to share


6 answers


If you are using Anchor, you will not be able to use the Dock (and vice versa).

Anchor and dock properties are mutually exclusive. Only one can be installed at a time, and the last installed has priority.



I would check if your control is the main control it thinks is its parent :-)). Also check the property Margin

on the control and Padding

on the parent control. Then check the property AutoSize

.

+1


a source


Check the docking and binding properties of the parent (UserControl). It looks to me like they haven't been set and the UserControl's non-items in the UserControl are expanding out of bounds.



+2


a source


I'm not really sure what you are talking about. Can you change the proposal?

If you say that when you resize the parent window, you want the control to resize as well, you are on the right track. You have to change the anchor so that the control is anchored to the left, top, right and bottom.

0


a source


If you want to dock to the right, at a constant height: anchor: = top, right If you want to dock to the bottom-right corner: anchor: = bottom, right

Which parent container do you go to? Is the control inside the parent? If not, then it can resize on top of it (since it's not really a child).

0


a source


The snapping may be fine, but the problem is with the rendering. Have you tried calling Invalidate () on your container? I remember that something similar happened to me a long time ago with the help of special control. And I resolved it by forcing the control to redraw.

0


a source


You may have to work around the z-order of the controls.

-2


a source







All Articles