• winform 子父窗体的设置,获取其子窗体


    1. 子父窗体的设置  以及判断是否其子窗体,存在子窗体是否Activate显示获取焦点。 呵呵 交流一下  有心得的朋友请探讨给点建议。

    2.    public class FormHelper
          {
              /// <summary>
              /// 设置子窗体
              /// </summary>
              /// <param name="type">类型</param>
              /// <param name="parent">父窗体</param>
              /// <returns></returns>
              public static Form ShowForm(Type type, Form parent)
              {
                  Form retForm;
                  if (!ChildExists(type, parent, true, out retForm))
                  {
                      ConstructorInfo[] cons = type.GetConstructors();
                      if (cons.Length > 0)
                      {
                          Object obj =cons[0].Invoke(null);
                          if (obj is Form)
                          {
                              retForm = obj as Form;
                              retForm.MdiParent = parent;
                              retForm.Show();
                              retForm.Activate();
                          }
                      }
                  }
                  return retForm;
              }
              /// <summary>
              /// 子窗体是否存在
              /// </summary>
              /// <param name="type">类型</param>
              /// <param name="parent">父窗体</param>
              /// <param name="showForm">是否显示</param>
              /// <param name="form">子窗体</param>
              /// <returns></returns>
              public static bool ChildExists(Type type, Form parent, bool showForm, out Form form)
              {
                  for (int i = 0; i < parent.MdiChildren.Length; i++)
                  {
                      Form child = parent.MdiChildren[i];
                      if (child.GetType() == type)
                      {
                          if (showForm)
                          {
                              child.Visible = true;
                              child.Activate();
                          }
                          form = child;
                          return true;
                      }
                  }
                  form = null;
                  return false;
              }
             
          }

    3.  Form f = Application.OpenForms["窗体名称"]; //查找窗体是否打开   存在则返回 窗体对象 否则null

  • 相关阅读:
    四、分配swap分区
    三、fdisk分区
    二、文件系统常用命令
    一、回顾分区和文件系统
    三、文件系统属性chattr权限&系统命令sudo权限
    2、开发环境搭建
    1、基本概念
    SSH服务
    CentOS 7安装启动vsftpd服务
    01.HTML 5与HTML4的区别
  • 原文地址:https://www.cnblogs.com/xiaoshuai/p/1752353.html
Copyright © 2020-2023  润新知