问题
I wish to have a Panel with the controls on it at design time but I want to add this panel to a desired tabPage of my TabControl at run time.
I wrote something like this, did not work : the panel does not show up in the tab page. please help me.
panel2.Parent = tabGuy.TabPages[0];
tabGuy.SuspendLayout();
tabGuy.TabPages[0].Controls.Add(panel2);
tabGuy.ResumeLayout();
panel2.Show();
回答1:
You probably need to set the coordinates of the Panel as well, or (better) panel2.Dock = DockStyle.Fill;
And you don't have to set the .Parent or call the .Show()
来源:https://stackoverflow.com/questions/2950321/adding-a-design-time-panel-to-a-tabpage-at-run-time