首先,我一直在搜索我的问题,但找不到 \help。所以我的问题是我有 3 个按钮和三个按钮userControl
,当我单击一个按钮时,它显示 usercontrol 1,但在我单击按钮 2 后。我无法返回 usercontrol 1,我卡在 usercontrol2 中,按钮 1 不再执行任何操作. 这是我的代码:
public partial class Form2 : Form
{
UserControl1 u1;
UserControl2 u2;
UserControl3 u3;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
u1 = new UserControl1();
u1.Dock = DockStyle.Fill;
this.Controls.Add(u1);
}
private void button2_Click(object sender, EventArgs e)
{
u1.Hide();
u2 = new UserControl2();
u2.Dock = DockStyle.Fill;
this.Controls.Add(u2);
}
private void button3_Click(object sender, EventArgs e)
{
u1.Hide();
u2.Hide();
u3 = new UserControl3();
u3.Dock = DockStyle.Fill;
this.Controls.Add(u3);
}
private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
为其他需要的人解决了代码:) --->
enter code here
public partial class Form2 : Form
{
UserControl1 u1;
UserControl2 u2;
UserControl3 u3;
public Form2()
{
u1 = new UserControl1();
u2 = new UserControl2();
u3 = new UserControl3();
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
u2.Hide();
u3.Hide();
u1.Show();
u1.Dock = DockStyle.Fill;
this.Controls.Add(u1);
}
private void button2_Click(object sender, EventArgs e)
{
u1.Hide();
u3.Hide();
u2.Show();
u2.Dock = DockStyle.Fill;
this.Controls.Add(u2);
}
private void button3_Click(object sender, EventArgs e)
{
u1.Hide();
u2.Hide();
u3.Show();
u3.Dock = DockStyle.Fill;
this.Controls.Add(u3);
}
private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
}
}