C# windows forms child window creation with VS
开发者_Python百科Let's say I have a basic form, there's a button and when I click it, it opens a new window. How can I do this? I tried creating a new form instance on button click event, but it gives me exception, that something is wrong.
Form frm = new Form();
frm.ShowDialog();
//frm.Show();
Or please share your code..
//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();
}
//hope this help
精彩评论