Ejemplo n.º 1
0
        /// 手动关闭当前页面
        /// <summary>
        /// 手动关闭当前页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainTabControl_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.Button == MouseButtons.Left)
                {
                    int x = e.X, y = e.Y;
                    //计算关闭区域
                    Rectangle myTabRect = this.tabControl1.GetTabRect(this.tabControl1.SelectedIndex);
                    myTabRect.Offset(myTabRect.Width - (CLOSE_SIZE + 3), 2);
                    myTabRect.Width  = CLOSE_SIZE;
                    myTabRect.Height = CLOSE_SIZE;
                    //如果鼠标在区域内就关闭选项卡
                    bool isClose        = x > myTabRect.X && x <myTabRect.Right &&
                                                                y> myTabRect.Y && y < myTabRect.Bottom;

                    if (isClose == true && !IsCurrentWindowIsCallingTel())
                    {
                        //仅仅剩下一个tab时返回
                        if (GetTabControlTabPagesCount() <= 1)
                        {
                            //取消代理
                            RefreshIESettings("");
                            GetCurrentBrowser().Navigate(DefaultURL);
                        }
                        else
                        {
                            if (WinformPages.Contains(this.tabControl1.SelectedTab.Name))
                            {
                                //关闭winform页面
                            }
                            else
                            {
                                WebBrowser mybor = GetCurrentBrowser();
                                //释放资源
                                mybor.Dispose();
                                mybor.Controls.Clear();
                            }
                            TabPage page = this.tabControl1.SelectedTab;
                            this.tabControl1.TabPages.Remove(page);
                            bool flag = alowReceiveCallMsg_WebpageIDList.Remove(page.Name);
                            Loger.Log4Net.Info("[MainUI] 手动关闭页面=" + page.Name + ",并且移除alowReceiveCallMsg_WebpageIDList[允许给iframe子页面推送话务消息列表]中的PageID:" + page.Name + ",结果=" + flag);
                            ShowTabPagesLog();
                            page.Dispose();
                            GC.Collect();
                        }
                    }
                    this.GetCurrentBrowser().Document.Window.Focus();
                    IHTMLWindow2 win = (IHTMLWindow2)this.GetCurrentBrowser().Document.Window.DomWindow;
                    win.focus();
                }
            }
            catch
            {
            }
        }