.net 父窗口线程交给子窗口

使用ApplicationContext

static class Program
    {
      internal static  ApplicationContext  context = new ApplicationContext(new Form1());
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();            
            Application.Run(context);
        }
    }

然后显示窗口:

            Form2 form = new Form2();
            Program.context.MainForm = form;
            form.Show();

这样就可以关闭父窗口。

posted @ 2014-01-18 14:05  UCanBeFree  阅读(104)  评论(0编辑  收藏  举报