參考網路 切換form 的教學, 自己練習
不知哪邊問題, 當Form3Btn1按下時,他無法關掉form3
有人可以幫我看一下哪邊錯嗎? 謝謝
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
Form Form2 = new Form();
Button Form2Btn1 = new Button();
Button Form2Btn2 = new Button();
Form Form3 = new Form();
Button Form3Btn1 = new Button();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2Btn1.Click += new EventHandler(Form2Btn1_Click);
Form2Btn1.DialogResult = DialogResult.OK;
Form2.Controls.Add(Form2Btn1);
Form2Btn2.Click += new EventHandler(Form2Btn2_Click);
Form2Btn2.DialogResult = DialogResult.Cancel;
Form2.Controls.Add(Form2Btn2);
Form2.ShowDialog(this);
}
protected void Form2Btn1_Click(object sender, EventArgs e)
{
Form3Btn1.Click += new EventHandler(Form3Btn1_Click);
Form3Btn1.DialogResult = DialogResult.OK;
Form3.Controls.Add(Form3Btn1);
Form3.ShowDialog(Form2);
}
protected void Form2Btn2_Click(object sender, EventArgs e)
{
}
protected void Form3Btn1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}