选项卡式窗体显示

  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;
                }
            }
        }

posted on 2012-10-25 13:45  酒歌  阅读(294)  评论(0编辑  收藏  举报