比winform的唯一页面要简便;
比如通过Form1打开Form2:
Form2中:
public partial class Form2 : Form { private Form2() //Form2的构造函数改为private私有 { InitializeComponent(); } private static Form2 f2 = null; public static Form2 getForm() { if (f2 == null || f2.IsDisposed) { f2 = new Form2(); } return f2; } }
Form1中:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form2 f2 = Form2.getForm(); f2.Show(); f2.Focus(); } }
webform与winform按钮点击事件都可以用button1.Click += button1_Click;