/// <summary> /// get the designer of the tab page corresponding to the supplied point. /// </summary> /// <param name="pt">point in the label area of the tab control</param> /// <returns></returns> private MgTabPage GetTabPageFromLocation(Point pt) { MgTabPage selectedTab = null; TabControl tab = (TabControl)Control; // loop over tab page labels rectangles, check if they contain our point for (int i = 0; i < tab.TabCount; i++) { Rectangle rect = tab.GetTabRect(i); // add the edges around the rectangles if (tab.Alignment == TabAlignment.Top || tab.Alignment == TabAlignment.Bottom) { rect.Y -= 2; rect.Height += 4; } else { rect.X -= 2; rect.Width += 4; } if (rect.Contains(pt)) { selectedTab = tab.TabPages[i] as MgTabPage; break; } } return(selectedTab); }
/// <summary> /// Get the TabPage over which a control is dragged, considering also the tab headers /// </summary> /// <param name="de"></param> /// <returns></returns> private TabPage GetDraggedOverTabPage(DragEventArgs de) { MgTabPage selectedTabPage = null; MgTabControl control = (MgTabControl)this.Control; // If the current point is not on the tab page Point pt = this.Control.PointToClient(new Point(de.X, de.Y)); if (!control.DisplayRectangle.Contains(pt)) { if (control.ClientRectangle.Contains(pt)) { // current point is in the labels area selectedTabPage = this.GetTabPageFromLocation(pt); } } else { selectedTabPage = (MgTabPage)control.SelectedTab; } return(selectedTabPage); }