C#_启动多个窗体winform

来源:互联网 发布:黑金ps知乎 编辑:程序博客网 时间:2024/05/21 22:42

启动多个窗体有很多方法,可以在Application.Run()中先实例化一个,然后在实例化出来的那个窗体的Onload,或者构造函数中实例化另一个窗体,这样在用户看来就是出现了两个窗体了。

MSDN上也有一种启动多个窗体的方法:

static class Program{    /// <summary>    /// 应用程序的主入口点。    /// </summary>    [STAThread]    static void Main()    {        Application.EnableVisualStyles();        Application.SetCompatibleTextRenderingDefault(false);        Application.Run(new MyapplicationContext());    }}class MyapplicationContext : ApplicationContext{    private void onFormClosed(object sender, EventArgs e)    {        if (Application.OpenForms.Count == 0)        {            ExitThread();        }    }    public MyapplicationContext()    {        var forms = new List<Form>(){            new ServiceClient(),            new frmInitial()        };        foreach (var form in forms)        {            form.FormClosed += onFormClosed;        }        foreach(var form in forms)        {            form.Show();        }    }}
0 0
原创粉丝点击