简体   繁体   中英

Location of controls got changed after adding it to a tabpage

I have winform application which uses a tabPage, and I dynamically added some controls into the page. However the location of the controls got changed after then. After some tweaking, it seems the location of the controls are correct, but the size of some controls are not correct again. Please help!!! thanks

The code snippet like this:

foreach (Control c in controls)
{
    Point oldLocation = c.Location;
    this.SuspendLayout();                                          
    this.Controls.Add(c);                        
    c.Location = oldLocation;                       
    c.BringToFront();
    this.ResumeLayout(false);
    this.PerformLayout();
}

I did not describe this in great detail probably. What I need is to have a floating tab page; so I ended up with keeping another form, and switch on/hide the form and the tab page when switch between floating and docking mode.

To achieve this, I need to copy/remove all the controls from either the form and the page. It turns out that the control location /size will be changed between the remove/copy.

The workaround I ended up with is to store the original location/size before I do the remove and copy, and reset the control's location and size afterward. It sounds a pretty lame solution, but I cannot find any better solution now.

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