选项卡式窗体显示

  private void ShowWindow(Form newForm)
        {
            newForm.MdiParent = this;
            //newForm.TopLevel = false;
            TabPage newpage = new TabPage(newForm.Text);
            newpage.Tag = newForm;
            newpage.Parent = tabShow;//设置新建tabpage父级为tabcontrol
            newForm.Parent = newpage;;//设置新建窗体newForm父级为tabpage
            this.tabShow.SelectedTab = newpage;
            newForm.Dock = DockStyle.Fill;
            newForm.Tag = tabShow.SelectedTab;
            newForm.FormBorderStyle = FormBorderStyle.None;
            newForm.FormClosed += new FormClosedEventHandler(newForm_FormClosed);
            newForm.Show();
        }

 /// <summary>
        /// 窗体关闭时移除该处选项卡
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void newForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Form newform = sender as Form;
            tabShow.TabPages.Remove(newform.Tag as TabPage);
        }
        //选项卡双击时关闭窗体移除选项卡
        private void tabShow_DoubleClick(object sender, EventArgs e)
        {
            if (tabShow.TabCount > 0)
            {
                Form fmShowDialog = (Form)tabShow.SelectedTab.Tag;
                fmShowDialog.Close();
            }
        }

 /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ExitButton_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        /// <summary>
        /// 菜单单击事件 显示窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void tmChild_Click(object sender, EventArgs e)
        {
                AddNewForwShow(sender);
        }

        private void AddNewForwShow(object sender)
        {
            bool IsExist = false;
            if (sender is ToolStripButton)
            {
                ToolStripButton tsbutton = sender as ToolStripButton;
                switch (tsbutton.Text)
                {
                    case "数据库备份":
                        DataTable dtShowDialog = new SJTD_HDYX.BLL.MenuForm().GetList(string.Format("mf_MenuID={0}", Convert.ToInt32(tsbutton.Tag))).Tables[0];
                        string str = "SJTD_HDYX." + dtShowDialog.Rows[0]["mf_FormName"].ToString();
                        //加载 窗体对象
                        Form fmShowDialog = (Form)Assembly.LoadFile(Application.StartupPath + "\\" + "SJTD_HDYX.exe").CreateInstance(str);
                        fmShowDialog.Text = tsbutton.Text;
                        fmShowDialog.ShowDialog();
                        break;
                    default:
                        foreach (TabPage tab in tabShow.TabPages)
                        {
                            if (tab.Text == tsbutton.Text)
                            {
                                IsExist = true;
                                tabShow.SelectedTab = tab;
                                break;
                            }
                        }
                        if (!IsExist)
                        {
                            DataTable dt = new SJTD_HDYX.BLL.MenuForm().GetList(string.Format("mf_MenuID={0}", Convert.ToInt32(tsbutton.Tag))).Tables[0];
                            if (dt.Rows.Count > 0)
                            {
                                string s = "SJTD_HDYX." + dt.Rows[0]["mf_FormName"].ToString();
                                //加载 窗体对象
                                Form fm = (Form)Assembly.LoadFile(Application.StartupPath + "\\" + "SJTD_HDYX.exe").CreateInstance(s);
                                fm.Text = tsbutton.Text;
                                ShowWindow(fm);
                            }
                        }
                        break;
                }
            }

            else if (sender is ToolStripMenuItem)
            {
                ToolStripMenuItem tsmenu = sender as ToolStripMenuItem;
                switch (tsmenu.Text)
                {
                    case "密码安全":
                    case "数据库备份":
                    case "热表更换":
                        DataTable dtShowDialog = new SJTD_HDYX.BLL.MenuForm().GetList(string.Format("mf_MenuID={0}", Convert.ToInt32(tsmenu.Tag))).Tables[0];
                        string str = "SJTD_HDYX." + dtShowDialog.Rows[0]["mf_FormName"].ToString();
                        //加载 窗体对象
                        Form fmShowDialog = (Form)Assembly.LoadFile(Application.StartupPath + "\\" + "SJTD_HDYX.exe").CreateInstance(str);
                        fmShowDialog.Text = tsmenu.Text;
                        fmShowDialog.ShowDialog();
                        break;
                    case "联系我们":
                        System.Diagnostics.Process.Start("www.yingcin.com");
                        break;
                    case "用户退出":
                        Application.Exit();
                        IsChangeUser = true;
                        break;
                    case "更换用户":
                        IsChangeUser = true;
                        this.DTUService.StopService();
                        this.Close();
                        break;
                    default:
                        foreach (TabPage tab in tabShow.TabPages)
                        {
                            if (tab.Text == tsmenu.Text)
                            {
                                IsExist = true;
                                tabShow.SelectedTab = tab;
                                break;
                            }
                        }
                        if (!IsExist)
                        {
                            DataTable dt = new SJTD_HDYX.BLL.MenuForm().GetList(string.Format("mf_MenuID={0}", Convert.ToInt32(tsmenu.Tag))).Tables[0];
                            if (dt.Rows.Count > 0)
                            {
                                string s = "SJTD_HDYX." + dt.Rows[0]["mf_FormName"].ToString();
                                //加载 窗体对象
                                Form fm = (Form)Assembly.LoadFile(Application.StartupPath + "\\" + "SJTD_HDYX.exe").CreateInstance(s);
                                fm.Text = tsmenu.Text;
                                ShowWindow(fm);
                            }
                        }
                        break;
                }
            }
        }

转载于:https://www.cnblogs.com/Iyce/archive/2012/10/25/2738673.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值