假设我有一个基本形式,有一个按钮,当我点击它时,它会打开一个新窗口。 我怎样才能做到这一点?我尝试在按钮点击事件上创建一个新的表单实例,但它给了我一个例外,那就是错误。
答案 0 :(得分:2)
Form frm = new Form();
frm.ShowDialog();
//frm.Show();
或者请分享您的代码..
答案 1 :(得分:0)
//assuming that ur first form is named Form1 and ur second form is Form2
//assuming that ur button is button1
//inside form1 something like this is shown
Button1.Click += new EventHandler(this.Button1_Click);
void Button1_Click(Object sender, EventArgs e){
Form2 form = new Form2();
//you do either
Form2.Show();
//or focus remains on form2 do this
Form2.ShowDialog();
}
//希望这个帮助