开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜