示例#1
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (this.Controls.Count > 0)
                {
                    int result = -1;
                    Rectangle smartButtonRectangle;
                    ClassLibrary.Winform.UI.Controls.PluggableTabControl.ButtonState smartButtonState;
                    GetSmartButtonHitTest(e.Location, out smartButtonRectangle,
                        out smartButtonState, out result);
                    switch (result)
                    {
                        /*** Is on the SmartCloseButton. ***/
                        case 0:
                            NeoTabPage stp = this.SelectedTab;
                            if (stp.IsCloseable)
                                Remove(stp);
                            break;
                        /*** Is on the SmartDropDownButton. ***/
                        case 1:
                            ContextMenuStrip dropDownMenu = new ContextMenuStrip();
                            Point menuLocation = PointToScreen(new Point(smartButtonRectangle.Left, smartButtonRectangle.Bottom));
                            using (DropDownButtonClickedEventArgs ea =
                                new DropDownButtonClickedEventArgs(dropDownMenu, menuLocation))
                            {
                                // Fire a Notification Event.
                                OnDropDownButtonClicked(ea);
                            }
                            break;
                        /*** Is not found! ***/
                        default:
                            if (this.Controls.Count > 1)
                            {
                                int itemIndex = -1;
                                Rectangle itemRectangle;
                                ClassLibrary.Winform.UI.Controls.PluggableTabControl.ButtonState itemState;
                                NeoTabPage tabItem = GetHitTest(e.Location,
                                    out itemRectangle, out itemState, out itemIndex);
                                if (tabItem != null && tabItem.IsSelectable)
                                {
                                    bool isAvailable = true;
                                    switch (this.TabItemLayout)
                                    {
                                        case TabItemLayout.Top:
                                        case TabItemLayout.Bottom:
                                            if (itemRectangle.Right >=
                                                (smartButtonRectangle.IsEmpty ? DisplayRectangle.Right : smartButtonRectangle.Left))
                                                isAvailable = false;
                                            break;
                                        default:
                                            if (itemRectangle.Bottom >=
                                                (smartButtonRectangle.IsEmpty ? DisplayRectangle.Bottom : smartButtonRectangle.Top))
                                                isAvailable = false;
                                            break;
                                    }
                                    if (isAvailable)
                                    {
                                        if (selectedIndex != itemIndex)
                                        {
                                            using (SelectedIndexChangingEventArgs ea =
                                                new SelectedIndexChangingEventArgs(tabItem, itemIndex))
                                            {
                                                // Fire a Notification Event.
                                                OnSelectedIndexChanging(ea);

                                                if (!ea.Cancel)
                                                    this.SelectedIndex = ea.TabPageIndex;
                                            }
                                        }
                                        else
                                        {
                                            if (!DesignMode && AllowDrop)
                                            {
                                                // Starts a drag & drop operation for currently selected tab page.
                                                BeginDragDrop(tabItem, itemRectangle,
                                                    ClassLibrary.Winform.UI.Controls.PluggableTabControl.ButtonState.Pressed, itemIndex);
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                    }
                }
            }
        }
示例#2
0
 protected virtual void OnDropDownButtonClicked(DropDownButtonClickedEventArgs e)
 {
     if (this.Controls.Count > 0)
     {
         ToolStripMenuItem menuItem = null;
         menuItem = new ToolStripMenuItem("Close", null, null,
             Keys.Control | Keys.C);
         menuItem.ImageScaling = ToolStripItemImageScaling.None;
         menuItem.Enabled = SelectedTab.IsCloseable ? true : false;
         if (menuItem.Enabled)
         {
             menuItem.Click += (sender, ea) =>
             {
                 Remove(SelectedTab);
             };
         }
         e.ContextMenu.Items.Add(menuItem);
         menuItem = new ToolStripMenuItem("Show/Hide Tab Items", null, null,
             Keys.Control | Keys.M);
         menuItem.ImageScaling = ToolStripItemImageScaling.None;
         menuItem.Click += (sender, ea) =>
         {
             ShowTabManager();
         };
         e.ContextMenu.Items.Add(menuItem);
         if (this.Controls.Count > 1)
         {
             e.ContextMenu.Items.Add(new ToolStripSeparator());
             int n = -1;
             foreach (NeoTabPage tp in this.TabPages)
             {
                 n++;
                 if (!tp.Equals(SelectedTab))
                 {
                     menuItem = new ToolStripMenuItem(tp.Text, null, null, n.ToString());
                     menuItem.ImageScaling = ToolStripItemImageScaling.None;
                     menuItem.Enabled = tp.IsSelectable ? true : false;
                     if (menuItem.Enabled)
                     {
                         menuItem.Click += (sender, ea) =>
                         {
                             OnNavigateTabPage(Int32.Parse(((ToolStripItem)sender).Name));
                         };
                     }
                     e.ContextMenu.Items.Add(menuItem);
                 }
             }
         }
         if (DropDownButtonClicked != null)
             DropDownButtonClicked(this, e);
         e.ContextMenu.Show(e.MenuLocation);
     }
 }