简体   繁体   中英

How to prevent usercontrol fill option from extending too far

I have a usercontrol that I'm adding as a control of a main form dynamically. The Mainform is basically empty, except it has a large status bar on bottom.

Problem is, when I set the Dockstyle.Fill option on my usercontrol, the size of the loaded usercontrol extends beyond the statusbar (It fills the entire main form as if the status bar wasn't there).

How do I prevent this behavior? This is an example of how I dynamically load my form

        logicForm = new LogicForm();
        this.Controls.Add(logicForm);
        logicForm.Dock = DockStyle.Fill;

I think you need to set the DockStyle to None and use the Anchor property instead.

Set the anchor to Top,Bottom,Left,Right and size your control to fill all the space up to the status bar.

You should find when you run that the user control will then resize with the form.

I just found the solution

I need to bring the form to front in order to properly dock it if I already have some other controls on the main form:

logicForm.BringToFront();

Found here: http://dotnetref.blogspot.kr/2008/08/using-dock-fill-on-control-when-you.html

-________________________-

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM