private void TabHeader_OnControlAdded(object sender, ControlEventArgs e) { if (typeof(TabButton).IsAssignableFrom(e.Control.GetType())) { TabButton tabButton = (TabButton)e.Control; tabButton.Click += new EventHandler(TabButton_OnClick); tabButton.CheckedChanged += new EventHandler(TabButton_OnCheckedChanged); #if DRAG_AND_DROP_SUPPORT tabButton.DragOver += new DragEventHandler(Control_DragOver); tabButton.DragDrop += new DragEventHandler(Control_DragDrop); tabButton.DragStarting += new DragEventHandler(Control_DragStarting); #endif } }
/// /// /// public TabHeader() { m_LeftFirst = 0; m_Scrolling = false; m_Multiselect = false; m_ActiveTab = null; m_LastShiftKeyTab = null; this.ControlAdded += new ControlEventHandler(TabHeader_OnControlAdded); this.ControlRemoved += new ControlEventHandler(TabHeader_OnControlRemoved); #if DRAG_AND_DROP_SUPPORT this.DragOver += new DragEventHandler(Control_DragOver); this.DragDrop += new DragEventHandler(Control_DragDrop); #endif }
protected override void OnHeaderButtonCheckedChanged(object sender, System.EventArgs e) { base.OnHeaderButtonCheckedChanged(sender, e); if (this.Visible) { if (this.SelectedButton == null) { foreach (Control c in Controls) { if (typeof(TabButton).IsAssignableFrom(c.GetType())) { TabButton tabButton = (TabButton)c; if (tabButton.Visible) { this.SelectedButton = tabButton; break; } } } } else { if (!this.SelectedButton.Checked) { this.SelectedButton.Checked = true; RefreshLayout(); OnSelectedTabChanged(System.EventArgs.Empty); } } } else { if (this.SelectedButton != null) { this.SelectedButton.Checked = false; RefreshLayout(); OnSelectedTabChanged(System.EventArgs.Empty); } } }
private void TabHeader_OnControlRemoved(object sender, ControlEventArgs e) { if (typeof(TabButton).IsAssignableFrom(e.Control.GetType())) { TabButton tabButton = (TabButton)e.Control; tabButton.Click -= new EventHandler(TabButton_OnClick); tabButton.CheckedChanged -= new EventHandler(TabButton_OnCheckedChanged); #if DRAG_AND_DROP_SUPPORT if (this.m_ActiveTab == tabButton) { this.m_ActiveTab = null; // unselect } if (this.m_LastShiftKeyTab == tabButton) { this.m_LastShiftKeyTab = null; // unselect } tabButton.DragOver -= new DragEventHandler(Control_DragOver); tabButton.DragDrop -= new DragEventHandler(Control_DragDrop); tabButton.DragStarting -= new DragEventHandler(Control_DragStarting); #endif } }
/*public void AddTab(int index, TabButton tab, Object o) * { * Controls.Add(tab); * RefreshLayout(); * }*/ // // // public void RefreshLayout() { int u, i; bool bs = !(m_SrcollRightButton == null || m_ScrollLeftButton == null); Size size = this.Size; Size isize; Size scrollersSize; if (bs) { isize = m_SrcollRightButton.Size; } else { isize = new Size(0, 0); } if (m_Vertical) { scrollersSize = new Size(isize.Width, isize.Height * 2 + 5); } else { scrollersSize = new Size(isize.Width * 2 + 5, isize.Height * 2); } // calculate the sum width of all tabs... need scroling???? int totalWidth = 0; int tabCnt = 0; ArrayList alWidths = new ArrayList(); foreach (Control c in Controls) { if (typeof(TabButton).IsAssignableFrom(c.GetType())) { TabButton tabButton = (TabButton)c; if (tabButton.Visible) { if (m_Vertical) { totalWidth += tabButton.Size.Height; alWidths.Add(tabButton.Size.Height); } else { totalWidth += tabButton.Size.Width; alWidths.Add(tabButton.Size.Width); } tabCnt++; } } } totalWidth += (tabCnt - 1) * m_Interval; #region Vertical if (m_Vertical) { if (totalWidth >= size.Height) { m_Scrolling = bs & true; size.Height -= scrollersSize.Height; if (m_LeftFirst < 0) { m_LeftFirst = 0; } // i = number of visible tabs from right side for (u = 0, i = 0; i < alWidths.Count; i++) { u += (int)alWidths[alWidths.Count - i - 1]; if (i > 0) { u += m_Interval; } if (u > size.Height) { break; } } if (m_LeftFirst > (tabCnt - i)) { m_LeftFirst = tabCnt - i; } } else { m_LeftFirst = 0; m_Scrolling = false; } } else { if (totalWidth >= size.Width) { m_Scrolling = true & bs; size.Width -= scrollersSize.Width; if (m_LeftFirst < 0) { m_LeftFirst = 0; } // i = number of visible tabs from right side for (u = 0, i = 0; i < alWidths.Count; i++) { u += (int)alWidths[alWidths.Count - i - 1]; if (i > 0) { u += m_Interval; } if (u > size.Width) { break; } } if (m_LeftFirst > (tabCnt - i)) { m_LeftFirst = tabCnt - i; } } else { m_LeftFirst = 0; m_Scrolling = false; } } #endregion // u = i = 0; foreach (Control c in Controls) { if (typeof(TabButton).IsAssignableFrom(c.GetType())) { TabButton tabButton = (TabButton)c; if (tabButton.Visible) { int ci = i++; if (m_LeftFirst > ci) { tabButton.BaseVisible = false; continue; } if (m_Vertical) { Size curImgSize = tabButton.Size; tabButton.SetBounds(0, u, curImgSize.Width, curImgSize.Height); u += curImgSize.Height; tabButton.BaseVisible = (m_LeftFirst == ci) || !(u > size.Height) | !bs; } else { Size curImgSize = tabButton.Size; tabButton.SetBounds(u, 0, curImgSize.Width, curImgSize.Height); u += curImgSize.Width; tabButton.BaseVisible = (m_LeftFirst == ci) || !(u > size.Width) | !bs; } u += m_Interval; } else { tabButton.BaseVisible = false; } } } #region Scrolling // if (m_Scrolling) { if (m_Vertical) { m_ScrollLeftButton.SetBounds(5, ClientRectangle.Bottom - scrollersSize.Height, isize.Width, isize.Height); m_SrcollRightButton.SetBounds(5, ClientRectangle.Bottom - scrollersSize.Height + isize.Width, isize.Width, isize.Height); } else { m_ScrollLeftButton.SetBounds(ClientRectangle.Right - scrollersSize.Width, (size.Height / 2) - (isize.Height / 2), isize.Width, isize.Height); m_SrcollRightButton.SetBounds(ClientRectangle.Right - scrollersSize.Width + isize.Width, (size.Height / 2) - (isize.Height / 2), isize.Width, isize.Height); } m_ScrollLeftButton.Visible = true; m_SrcollRightButton.Visible = true; } else { if (m_ScrollLeftButton != null) { m_ScrollLeftButton.Visible = false; } if (m_SrcollRightButton != null) { m_SrcollRightButton.Visible = false; } } #endregion }
private void TabButton_OnClick(object sender, System.EventArgs e) { if (sender == null || !typeof(TabButton).IsAssignableFrom(sender.GetType())) { return; } TabButton currentButton = (TabButton)sender; if (!m_Multiselect) { m_LastShiftKeyTab = null; this.SelectedButton = currentButton; } else { // Multiselect System.Windows.Forms.Keys keys = ModifierKeys; bool bCtrlPressed = (keys & Keys.Control) == Keys.Control; bool bShiftPressed = (keys & Keys.Shift) == Keys.Shift; if (bCtrlPressed) { m_LastShiftKeyTab = null; if (currentButton != null) { currentButton.Checked = !currentButton.Checked; } if (m_ActiveTab == currentButton) { if (!currentButton.Checked) { m_ActiveTab = null; // m_ActiveTab = first checked foreach (Control c in Controls) { if (typeof(TabButton).IsAssignableFrom(c.GetType())) { TabButton tabButton = (TabButton)c; if (tabButton.Visible && tabButton.Checked) { m_ActiveTab = tabButton; break; } } } // foreach } } else { m_ActiveTab = currentButton; } } else if (bShiftPressed && currentButton != null) { // TODO: ShiftKeyUp -- m_ActiveTab = currentButton m_LastShiftKeyTab = currentButton; int first = -1, last = -1, m = -1; // has no selection ? m_ActiveTab = first item from container if (m_ActiveTab == null) { foreach (Control c in Controls) { if (typeof(TabButton).IsAssignableFrom(c.GetType())) { TabButton tabButton = (TabButton)c; if (tabButton.Visible) { m_ActiveTab = tabButton; break; } } } } // get btn range to be checked if (m_Vertical) { first = currentButton.Top + currentButton.Height / 2; last = m_ActiveTab.Top + m_ActiveTab.Height / 2; } else { first = currentButton.Left + currentButton.Width / 2; last = m_ActiveTab.Left + m_ActiveTab.Width / 2; } if (first > last) { m = last; last = first; first = m; } // check btns foreach (Control c in Controls) { if (typeof(TabButton).IsAssignableFrom(c.GetType())) { TabButton tabButton = (TabButton)c; if (tabButton.Visible) { if (m_Vertical) { m = tabButton.Top + tabButton.Height / 2; } else { m = tabButton.Left + tabButton.Width / 2; } if (first <= m && last >= m) { tabButton.Checked = true; } else { tabButton.Checked = false; } } } } // foreach } else { foreach (Control c in Controls) { if (typeof(TabButton).IsAssignableFrom(c.GetType())) { TabButton tabButton = (TabButton)c; tabButton.Checked = currentButton == tabButton; } } m_ActiveTab = currentButton; } RefreshLayout(); OnSelectedTabChanged(System.EventArgs.Empty); } }