• 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

  • 相关阅读:
    c++ socket发送数据时,sendData = char * string 导致的乱码问题
    c++ sprintf() 用法
    c++ 将float 类型转换成string 类型
    c++中 string类型 转为 char []类型
    c++ 去掉所有空格及换行符
    c++处理字符串string.find()与string::npos
    C1010 unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source
    C++ socket bind() 函数绑定错误
    windows 全局安装 composer
    VMware Tools (ubuntu系统)安装详细过程与使用
  • 原文地址:https://www.cnblogs.com/xiaoshuai/p/1752353.html
Copyright © 2020-2023  润新知