这也是前两天课程中的案例。讨论的是,MDI子窗体是否也可以实现单实例

这当然是可以做到的,我们通过下面这个方法来做就可以了
        private void ShowMdiChildForm(Type formType,bool singleinstance,params object[] args)
        {
            //这个方法可以加载任何的窗口作为MDI子窗体


            if (singleinstance) {
                foreach (var item in this.MdiChildren)
                {
                    if (item.GetType() == formType)
                    {
                        item.WindowState = FormWindowState.Maximized;
                        item.Activate();
                        return;
                    }
                }
            }

            Form form = (Form)this.GetType().Assembly.CreateInstance(
                formType.FullName,
                true,
                BindingFlags.Instance| BindingFlags.Public,
                null,args,
                Thread.CurrentThread.CurrentCulture,
                null);


            form.WindowState = FormWindowState.Maximized;
            form.MdiParent = this;
            form.Show();
        }

相关文章:

  • 2021-10-23
  • 2021-08-22
  • 2022-12-23
  • 2021-12-26
  • 2021-09-20
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
猜你喜欢
  • 2022-01-22
  • 2017-11-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案