我是c#编码的新手,希望这个问题不会打扰任何人:)
我正在尝试学习在win表单中使用用户控件。在下面的代码中,当我运行我的代码时,它显示2个menustrip而不是一个。
public partial class MainForm : Form
{
//user control
private mdi2.UserControls.UCForm1 ucForm1;
private mdi2.UserControls.UCForm2 ucForm2;
public MainForm()
{
InitializeComponent();
InitializeComponent();
// Instantiate the User Controls
ucForm1 = new mdi2.UserControls.UCForm1();
this.Controls.Add(ucForm1);
ucForm2 = new mdi2.UserControls.UCForm2();
this.Controls.Add(ucForm2);
}
private void MainForm_Load(object sender, EventArgs e)
{
}
private void uCForm1ToolStripMenuItem_Click(object sender, EventArgs e)
{
ucForm1.Visible = true;
ucForm1.Dock = DockStyle.Fill;
ucForm1.BringToFront();
}
private void uCForm2ToolStripMenuItem_Click(object sender, EventArgs e)
{
ucForm2.Visible = true;
ucForm2.Dock = DockStyle.Fill;
ucForm2.BringToFront();
}
}
答案 0 :(得分:4)