private void closeTabsToTheRightToolStripMenuItem_Click(object sender, EventArgs e) { for (var i = SelectedIndex + 1; TabPages[i] != SelectedTab && TabPages[i] != addTabPage;) { TabPages.RemoveAt(i); } }
private void ItemCloseAll_Clicked(object sender, EventArgs e) { for (int i = TabCount - 1; i > 0; i--) { TabPages.RemoveAt(i); } }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); //鼠标中间关闭选中 if (e.Button == MouseButtons.Middle && TabPages.Count > 1) { for (var i = 0; i < TabPages.Count; i++) { if (GetTabRect(i).Contains(e.Location)) { if (TabPageClose != null) { TabPageClose(this, EventArgs.Empty); } TabPages.RemoveAt(i); return; } } } //单击叉叉关闭 if (CloseRect.Contains(e.Location) && closeState == MouseState.press && e.Button == MouseButtons.Left) { if (TabPageClose != null) { TabPageClose(this, EventArgs.Empty); } if (TabPages.Count > 1) { TabPages.RemoveAt(SelectedIndex); } } }
private void OnItemClicked(object s, EventArgs e) { if (_tabIndex != -1) { TabPages.RemoveAt(_tabIndex); _tabIndex = -1; } }
public void HidePage(TabPage tabPage) { if (TabPages.Contains(tabPage)) { int v = TabPages.IndexOf(tabPage); HiddenPages.Add(tabPage); lastIndex.Add(v); TabPages.RemoveAt(v); } }
protected override void OnMouseUp(MouseEventArgs e) { try { Point mouse = MousePosition; if (ClientRectangle.Contains(PointToClient(mouse))) { if (e.Button == MouseButtons.Left) { if (CurrentCloser != -1 && Closers) { if (SelectedIndex > 0 && SelectedIndex == CurrentTab) { SelectedIndex -= 1; } OnPageClose?.Invoke(this, new ClosingEventArgs(CurrentCloser)); TabPages.RemoveAt(CurrentCloser); CurrentTab = SelectedIndex; if (CurrentTab == -1) { return; } if (CloserRect(CurrentTab).Contains(PointToClient(mouse))) { CurrentCloser = CurrentTab; } else if (CurrentCloser != -1) { CurrentCloser = -1; } return; } else { SelectedIndex = CurrentTab; } mouseDown = false; } } } catch (Exception ex) { //MessageBoxTi.Show("TabControlTi.OnMouseUp " + ex.Message); } base.OnMouseUp(e); }
private void CloseAll_Click(object sender, EventArgs e) { TabPage current = (TabPage)contextMenuStrip.Tag; for (int i = TabPages.Count - 1; i >= 0; i--) { if (TabPages[i] != current && (((EditorTab)TabPages[i]).CanClose())) { TabPages.RemoveAt(i); } } }
protected override void OnMouseClick(System.Windows.Forms.MouseEventArgs e) { if (_TabCloseButton & TabCount > 1) { int intHoveredIndex = GetHoveredCloseButtonIndex(e.Location); if (intHoveredIndex != -1) { TabPages.RemoveAt(intHoveredIndex); } } base.OnMouseClick(e); }
private void CloseTab(int i) { if (PreRemoveTabPage != null) { bool closeIt = PreRemoveTabPage(i); if (!closeIt) { return; } } TabPages.RemoveAt(i); }
public void OnRemove(object sender, EventArgs args) { int index = SelectedIndex; if (TabCount == 1) { AddPage(); } TabPages.RemoveAt(index); SelectedIndex = Math.Max(0, index - 1); }
protected override void OnKeyDown(KeyEventArgs ke) { base.OnKeyDown(ke); if (ke.KeyData == Keys.Escape) { int tabIndex = SelectedIndex; if (tabIndex > 0) { TabPages.RemoveAt(tabIndex); SelectedIndex = tabIndex - 1; } } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); for (int i = 0; i < this.TabPages.Count; i++) { if (this.GetTabRect(i).Contains(e.Location)) { if (xbtn.XRect(i).Contains(e.Location) && e.Button == MouseButtons.Left) { TabPages.RemoveAt(this.SelectedIndex); } break; } } }
private void MouseMoveHandler(object sender, MouseEventArgs e) { if (null == TabPageDragDrop) { return; // No DragDrop currently active } if (e.Button != MouseButtons.Left) { // Should be coverd by MouseUp, just for safety // DragDrop stopped TabPageDragDrop = null; } else { // During DragDrop TabPage hover_Tab = GetTabUnderMouse(); if ((hover_Tab == null) || (hover_Tab == TabPageDragDrop)) { return; // Dragged onto nothing or itself? } if (hover_Tab.Text.Equals("+") || hover_Tab.Text.Equals("-")) { return; // Keep "New"/"Delete" tab at the end } // Switch tabs but retain numbering int Index1 = TabPages.IndexOf(TabPageDragDrop); int Index2 = TabPages.IndexOf(hover_Tab); ProfileTabPermutingHandler(this, new Tuple <int, int>(Index1, Index2)); // How to swtich tabs... // - Just overwrite the references to the pages at the specific indicies: // On Windows working solution but will remove entries using Mono. // TabPages[Index1] = hover_Tab; // TabPages[Index2] = TabPageDragDrop; // - Modifying index of one to move it around: // On Mono working solution, but on Windows it seems it does not update order in TabPages // Controls.SetChildIndex(hover_Tab, Index1); // - Be pragmatic and remove one tab and insert it at the new position again: works.. TabPages.RemoveAt(Index1); TabPages.Insert(Index2, TabPageDragDrop); hover_Tab.Text = (Index1 + 1).ToString(); TabPageDragDrop.Text = (Index2 + 1).ToString(); SelectedTab = TabPageDragDrop; } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); var closeButtonSize = _closeButtonSize.Value; for (int i = 0; i < TabPages.Count; i++) { var tabRectangle = GetTabRect(i); var tabCloseButton = new Rectangle(tabRectangle.Right - CloseButtonPadding, tabRectangle.Top + Padding.Y, closeButtonSize.Width, closeButtonSize.Height); if (tabCloseButton.Contains(e.Location)) { TabPages.RemoveAt(i); break; } } }
private void TabControlEx_MouseDown(object sender, MouseEventArgs e) { if (TabCount == 0) { return; } var lastIndex = TabCount - 1; if (GetTabRect(lastIndex).Contains(e.Location)) { var newTabPage = new TabPage(); if (TabPageAdding != null && TabPageAdding(this, new TabPageEventArgs(newTabPage))) { TabPages.Insert(lastIndex, newTabPage); SelectedIndex = lastIndex; TabPages[lastIndex].UseVisualStyleBackColor = true; } } else { for (var i = 0; i < TabPages.Count; i++) { var tabRect = GetTabRect(i); tabRect.Inflate(-2, -2); var closeImage = Properties.Resources.Close; var imageRect = new Rectangle( (tabRect.Right - closeImage.Width), tabRect.Top + (tabRect.Height - closeImage.Height) / 2, closeImage.Width, closeImage.Height); if (imageRect.Contains(e.Location)) { if (TabPageDeleting != null && TabPageDeleting(this, new TabPageEventArgs(TabPages[i]))) { TabPages.RemoveAt(i); } break; } } } }
private void Swap(TabPage a, TabPage b) { int iA = TabPages.IndexOf(a); int iB = TabPages.IndexOf(b); int d = GetTabRect(iA).Width - GetTabRect(iB).Width; if (tabsSwapped != null) { tabsSwapped(this, new TabsSwappedEventArgs(iA, iB)); } TabPages.RemoveAt(iB); TabPages.Insert(iA, b); if (d < -1) { Cursor.Position = new Point((iA > iB) ? Cursor.Position.X + d : Cursor.Position.X - d, Cursor.Position.Y); } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button != MouseButtons.Left) { return; } for (int i = 0; i < TabPages.Count; i++) { Rectangle bounds = GetTabRect(i); Rectangle closeButtonBounds = new Rectangle(bounds.Right - 15, bounds.Top + 5, 15, bounds.Height - 10); if (closeButtonBounds.Contains(e.Location)) { TabPages.RemoveAt(i); OnTabClosed(new EventArgs()); } } }
private void OnTabCloseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Left && _HoverTabIndex != -1 && _CloseButtonTarget.Contains(e.Location) || e.Button == MouseButtons.Middle && _HoverTabIndex != -1) { var tabIndex = _HoverTabIndex; TabClosing?.Invoke(new TabsEventArgs() { TabIndex = tabIndex }); if (tabIndex > -1) { TabPages.RemoveAt(tabIndex); SelectedIndex = tabIndex != TabPages.Count ? tabIndex : TabPages.Count - 1; } } }
protected override void OnPreviewKeyDown(KeyEventArgs e) { if (Keyboard.Modifiers == ModifierKeys.Control) { switch (e.Key) { case Key.F4 when CanCloseCurrentTab(): case Key.W when CanCloseCurrentTab(): { // Closes the active tab (if it is closeable) TabPages.RemoveAt(SelectedTabIndex); e.Handled = true; return; } case Key.PageDown: { // Go to the next tab SelectedTabIndex = (SelectedTabIndex + 1) % TabPages.Count; OnPropertyChanged(nameof(SelectedTabIndex)); e.Handled = true; return; } case Key.PageUp: { // Go to previous tab SelectedTabIndex = (SelectedTabIndex - 1 + TabPages.Count) % TabPages.Count; OnPropertyChanged(nameof(SelectedTabIndex)); e.Handled = true; return; } } } base.OnPreviewKeyDown(e); bool CanCloseCurrentTab() => SelectedTabIndex >= 0 && SelectedTabIndex < TabPages.Count && TabPages[SelectedTabIndex].CanClose; }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); for (int i = 0; i < TabPages.Count; i++) { Rectangle bounds = GetTabRect(i); int offset = (bounds.Height - 16) / 2; Rectangle closeButton = new Rectangle(bounds.X + bounds.Width - 20, bounds.Y + offset, 14, 16); if (closeButton.Contains(e.Location)) { if (MessageBox.Show(onCloseMsg, "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { TabPages.RemoveAt(i); break; } } } }
protected override void WndProc(ref Message m) { if (m.Msg == TCM_SETPADDING) { m.LParam = MAKELPARAM(this.Padding.X + CloseButtonHeight / 2, this.Padding.Y); } if (m.Msg == WM_MOUSEDOWN && !this.DesignMode) { Point pt = this.PointToClient(Cursor.Position); Rectangle closeRect = GetCloseButtonRect(HotTabIndex); if (closeRect.Contains(pt)) { TabPages.RemoveAt(HotTabIndex); m.Msg = WM_NULL; } } base.WndProc(ref m); }
internal void RemoveTabPage(int index) { if (index < 0 || index >= tabPageCount) { throw new ArgumentException("tabControl.RemoveTabPage(index)"); } tabPageCount--; TabPages.RemoveAt(index); Controls.Remove(pagesButtons[index]); pagesButtons.RemoveAt(index); if (selectedIndex == tabPageCount) { SelectedIndex = tabPageCount - 1; } SelectTab(SelectedIndex); UpdateButtons(); }
protected override void OnMouseDown(MouseEventArgs e) { azalan = 0; base.OnMouseDown(e); // TabPage MevcutTabPage = tabControlZ1.SelectedTab; //TabPage MevcutTabPage= this.TabPages. //tabControlZ1.TabPages.Remove(MevcutTabPage); for (int i = 0; i < this.TabPages.Count; i++) { Rectangle r = this.GetTabRect(i); Rectangle closeButton = new Rectangle(r.Right + 1 - 15, r.Top + 4, 12, 12); if (closeButton.Contains(e.Location)) //if(closeButton.Contains(this.PointToClient() { //if (MessageBox.Show("Do you want to Close this Tab ?", "Close or Not", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) //{ TabPages.RemoveAt(i); break; } } }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (MouseDownIndex < 0) { return; } if (GetCloseBtnRect(MouseDownIndex).Contains(e.Location)) { CancelEventArgs args = new CancelEventArgs(false); TabClosing?.Invoke(this, args); if (!args.Cancel) { TabPages.RemoveAt(MouseDownIndex); } } MouseDownIndex = -1; Invalidate(); }
protected virtual void CloseTab(int index) { TabPages.RemoveAt(index); }
public virtual void CloseTab(int index) { TabPages.RemoveAt(index); }