public class YourPanel : UserControl
{
private Panel panel1;
...
}public class mainForm : Form
{
private YourPanel yourPanel1;
public void mainForm()
{
yourPanel1 = new YourPanel();
yourPanel1.Location = new Point(10,10);
yourPanel1.Size = new Size(100,100);
this.Controls.Add(yourPanel1);
}
}
{
private Panel panel1;
...
}public class mainForm : Form
{
private YourPanel yourPanel1;
public void mainForm()
{
yourPanel1 = new YourPanel();
yourPanel1.Location = new Point(10,10);
yourPanel1.Size = new Size(100,100);
this.Controls.Add(yourPanel1);
}
}
如果设这样的话,你把form的panel声明为public就行了。