Beispiel #1
0
        /// <summary>
        /// TabControl点击关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainTabControl_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)//鼠标左键点击事件
            {
                int       x       = e.X;
                int       y       = e.Y;
                Rectangle tabRect = this.MainTabControl.GetTabRect(this.MainTabControl.SelectedIndex);
                tabRect.Offset(tabRect.Width - 0x12, 2);
                tabRect.Width  = 15;
                tabRect.Height = 15;
                if ((((x > tabRect.X) && (x < tabRect.Right)) && (y > tabRect.Y)) && (y < tabRect.Bottom))
                {
                    this.MainTabControl.TabPages.Remove(this.MainTabControl.SelectedTab);
                }
            }


            if (e.Button == MouseButtons.Right) //实现右键选中选项卡
            {
                for (int i = 0; i < MainTabControl.TabPages.Count; i++)
                {
                    TabPage tp = MainTabControl.TabPages[i];
                    if (MainTabControl.GetTabRect(i).Contains(new Point(e.X, e.Y)))
                    {
                        MainTabControl.SelectedTab = tp;
                        break;
                    }
                }
                this.MainTabControl.ContextMenuStrip = this.contextMenuTabPage;  //弹出菜单
            }
        }
Beispiel #2
0
        private void MainTabControl_DragDrop(object sender, DragEventArgs e)
        {
            TabPage source = (TabPage)e.Data.GetData(typeof(TabPage));

            SetCurrStatus($"MainTabControl_DragDrop:{source}");
            if (source != null)
            {
                for (int i = 0; i < MainTabControl.TabPages.Count; i++)
                {
                    if (MainTabControl.GetTabRect(i).Contains(e.X, e.Y))
                    {
                        //var tab = MainTabControl.TabPages[i];
                        //SetCurrStatus($"拖动开始:{MainTabControl.TabPages[i].Text},AlowDrop:{tab.AllowDrop}");
                        //tab.DoDragDrop(e, DragDropEffects.Move);
                        if (MainTabControl.TabPages.IndexOf(source) != i)
                        {
                            e.Effect = DragDropEffects.Move;
                            TabAdapter.Swap(MainTabControl.TabPages.IndexOf(source), i);
                            SetCurrStatus($"拖动结束:{e.Data}");
                            return;
                        }
                    }
                }
            }
            e.Effect = DragDropEffects.None;
        }
Beispiel #3
0
 private void MainTabControl_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         for (int i = 0; i < MainTabControl.TabPages.Count; i++)
         {
             if (MainTabControl.GetTabRect(i).Contains(new Point(e.X, e.Y)))
             {
                 MainTabControl.SelectedIndex = i;
                 //var node = MainTabControl.TabPages[i].Tag as ITabPageNode;
                 //if(node != null)
                 //{
                 //    SetCurrStatus($"Tab Page Data: {JsonConvert.SerializeObject(node)}");
                 //}
                 SetCurrStatus($"右键打开并操作:{MainTabControl.TabPages[i].Text}");
             }
         }
     }
     if (e.Button == MouseButtons.Left)
     {
         for (int i = 0; i < MainTabControl.TabPages.Count; i++)
         {
             if (MainTabControl.GetTabRect(i).Contains(e.Location))
             {
                 var tab = MainTabControl.TabPages[i];
                 SetCurrStatus($"拖动开始:{tab.Text}");
                 tab.DoDragDrop(tab, DragDropEffects.All);
             }
         }
     }
 }
Beispiel #4
0
        private void tabControlMain_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point     p = e.Location;
                Rectangle r = MainTabControl.GetTabRect(this.MainTabControl.SelectedIndex);
                r.Offset(r.Width - iconWidth, 4);
                r.Width  = iconWidth;
                r.Height = iconHeight;
                if (this.MainTabControl.SelectedTab.Text == nodeMonitorView.Text)
                {
                    return;
                }
                string tabText = this.MainTabControl.SelectedTab.Text;

                if (r.Contains(p))
                {
                    this.childList.Remove(tabText);
                    this.MainTabControl.TabPages.RemoveAt(this.MainTabControl.SelectedIndex);
                }

                //int x = e.X, y = e.Y;

                ////计算关闭区域
                //Rectangle myTabRect = this.MainTabControl.GetTabRect(this.MainTabControl.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)
                //{
                //    if (this.MainTabControl.SelectedTab.Text == nodeMonitorView.Text)
                //    {
                //        return;
                //    }
                //    string tabText = this.MainTabControl.SelectedTab.Text;
                //    this.childList.Remove(tabText);
                //    this.MainTabControl.TabPages.Remove(this.MainTabControl.SelectedTab);

                //}
            }
        }
Beispiel #5
0
        public TabPage GetClickedTab(MouseEventArgs e)
        {
            TabPage page = null;

            try
            {
                page = MainTabControl.TabPages.Cast <TabPage>()
                       .Where((t, i) =>
                              MainTabControl.GetTabRect(i)
                              .Contains(e.Location)).First();
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message);
            }

            return(page);
        }
Beispiel #6
0
        private void MainTabControl_DragOver(object sender, DragEventArgs e)
        {
            TabPage source = (TabPage)e.Data.GetData(typeof(TabPage));

            //SetCurrStatus($"MainTabControl_DragOver:{source}");
            if (source != null)
            {
                for (int i = 0; i < MainTabControl.TabPages.Count; i++)
                {
                    if (MainTabControl.GetTabRect(i).Contains(MainTabControl.PointToClient(new Point(e.X, e.Y))))
                    {
                        if (MainTabControl.TabPages.IndexOf(source) != i)
                        {
                            e.Effect = DragDropEffects.Move;
                            TabAdapter.Swap(MainTabControl.TabPages.IndexOf(source), i);
                            MainTabControl.SelectedTab = source;
                            SetCurrStatus($"拖动结束:{source.Text}");
                            return;
                        }
                    }
                }
            }
            e.Effect = DragDropEffects.None;
        }
Beispiel #7
0
        private void tabControlMain_DrawItem(object sender, DrawItemEventArgs e)
        {
            try
            {
                Image     icon      = this.imageList1.Images[0];
                Brush     biaocolor = Brushes.Transparent; //选项卡的背景色
                Graphics  g         = e.Graphics;
                Rectangle r         = MainTabControl.GetTabRect(e.Index);
                if (e.Index == this.MainTabControl.SelectedIndex) //当前选中的Tab页,设置不同的样式以示选中
                {
                    Brush selected_color = Brushes.Wheat;         //选中的项的背景色
                    g.FillRectangle(selected_color, r);           //改变选项卡标签的背景色
                    string title = MainTabControl.TabPages[e.Index].Text + "  ";

                    g.DrawString(title, this.Font, new SolidBrush(Color.Black), new PointF(r.X, r.Y + 6));//PointF选项卡标题的位置

                    r.Offset(r.Width - iconWidth - 3, 2);
                    g.DrawImage(icon, new Point(r.X + 2, r.Y + 2));//选项卡上的图标的位置 fntTab = new System.Drawing.Font(e.Font, FontStyle.Bold);
                }
                else//非选中的
                {
                    g.FillRectangle(biaocolor, r); //改变选项卡标签的背景色
                    string title = this.MainTabControl.TabPages[e.Index].Text + "  ";

                    g.DrawString(title, this.Font, new SolidBrush(Color.Black), new PointF(r.X, r.Y + 6)); //PointF选项卡标题的位置
                    r.Offset(r.Width - iconWidth - 3, 2);
                    g.DrawImage(icon, new Point(r.X + 2, r.Y + 2));                                        //选项卡上的图标的位置
                }
                //Rectangle myTabRect = this.MainTabControl.GetTabRect(e.Index);

                ////先添加TabPage属性
                //e.Graphics.DrawString(this.MainTabControl.TabPages[e.Index].Text
                //, this.Font, SystemBrushes.ControlText, myTabRect.X + 2, myTabRect.Y + 2);

                //myTabRect.Offset(myTabRect.Width - (CLOSE_SIZE + 3), 2);
                //myTabRect.Width = CLOSE_SIZE;
                //myTabRect.Height = CLOSE_SIZE;
                ////再画一个矩形框
                //using (Pen p = new Pen(Color.Red))
                //{

                //    //  e.Graphics.DrawRectangle(p, myTabRect);
                //}


                ////画关闭符号
                //using (Pen objpen = new Pen(Color.DarkGray, 1.0f))
                //{
                //    //"\"线
                //    Point p1 = new Point(myTabRect.X + 3, myTabRect.Y + 3);
                //    Point p2 = new Point(myTabRect.X + myTabRect.Width - 3, myTabRect.Y + myTabRect.Height - 3);
                //    e.Graphics.DrawLine(objpen, p1, p2);

                //    //"/"线
                //    Point p3 = new Point(myTabRect.X + 3, myTabRect.Y + myTabRect.Height - 3);
                //    Point p4 = new Point(myTabRect.X + myTabRect.Width - 3, myTabRect.Y + 3);
                //    e.Graphics.DrawLine(objpen, p3, p4);
                //}

                //e.Graphics.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }