zoukankan      html  css  js  c++  java
  • c/s winForm框架 tabpage标签切换窗体

    /// <summary>
    /// 根据窗体Name打开窗体
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public Form FindForm(string name)
    {
    Assembly assembly = Assembly.GetExecutingAssembly();
    // 实例化窗体
    Form form = assembly.CreateInstance(DBConfig.GetConfigValue("Namespace") + name) as Form;
    return form;
    }

    /// <summary>
    /// 左侧菜单树点击
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
    {
    if (e.Node.Tag != null)
    {

    Form FormChild = FindForm(e.Node.Tag.ToString());

    if (FormChild != null)
    {
    ShowChildForm(FormChild);
    }
    //else
    //{
    // MessageBoxEx.Show("当前窗体不存在");
    //}
    }

    }

    /// <summary>
    /// 窗体切换
    /// </summary>
    /// <param name="form"></param>
    private void ShowChildForm(Form form)
    {
    if (!FindTabPageForm(form.Name))
    {
    //获取能打开的窗体数
    int sysTabPageNum =T2THelper.ToInt32(DBConfig.GetConfigValue("sysTabpageNum"), 5);
    if (sysTabPageNum > tabControl1.TabPages.Count)
    {
    TabPage tp = new TabPage();
    //将form的名称给tabpage
    tp.Name = form.Name;
    tp.Text = form.Text;
    tabControl1.TabPages.Add(tp);
    tabControl1.SelectedTab = tp;
    form.FormBorderStyle = FormBorderStyle.None;
    form.MdiParent = this;
    //这比较关键,给出窗体的父容器为tabpage
    form.Parent = tp;
    form.Dock = DockStyle.Fill;
    form.Show();
    }
    else
    {
    MessageBoxEx.Show("您好 只能同时打开" + sysTabPageNum.ToString() + "个窗口,请关于其他窗口后再打开", "提醒");
    }
    }
    else
    {
    tabControl1.SelectedTab = GetTabPageForm(form.Name);
    }

    }

    /// <summary>
    /// 判断TabPage是否已经打开
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public bool FindTabPageForm(string name)
    {
    foreach (TabPage tp in tabControl1.TabPages)
    {
    if (name == tp.Name)
    {
    return true;
    }
    }
    return false;
    }

    示例图

  • 相关阅读:
    Lua大整数的实现
    std::allocator在stl容器中使用问题
    深度学习框架安装
    Tensorflow安装使用一段时间后,import时出现错误:ImportError: DLL load failed
    论文解读:SIFA
    多位微软MVP推荐,第一本ASP.NET Core 3.1的书来了
    ASP.NET Core 进程内与进程外的性能对比
    基于Netty的程序主动发送消息
    dbroot文件结构解析(一)
    qtree文件结构解析(二)
  • 原文地址:https://www.cnblogs.com/manage/p/8358481.html
Copyright © 2011-2022 走看看