public GetTabRect ( int index ) : Rectangle | ||
index | int | |
Результат | Rectangle |
protected override void WndProc(ref Message m) { base.WndProc(ref m); // Selection of tabs via mouse if (m.Msg == 0x201 /*WM_LBUTTONDOWN*/) { System.Windows.Forms.TabControl control = (System.Windows.Forms.TabControl)Component; int lParam = m.LParam.ToInt32(); Point hitPoint = new Point(lParam & 0xffff, lParam >> 0x10); if (Control.FromHandle(m.HWnd) == null) // Navigation { if (hitPoint.X < 18 && control.SelectedIndex > 0) // Left { control.SelectedIndex--; } else { control.SelectedIndex++; // Right } } else // Header click { for (int i = 0; i < control.TabCount; i++) { if (control.GetTabRect(i).Contains(hitPoint)) { control.SelectedIndex = i; return; } } } } }
private void ViewForm_Load(object sender, System.EventArgs e) { this.Left = Owner.Right + 1; this.Top = Owner.Top; StrokeTabs.Dock = DockStyle.Fill; ViewForm_Resize(null, EventArgs.Empty); if (_prototypes.Count == 0) { StrokeTabs.Visible = false; lblNone.Visible = true; } else { foreach (Gesture p in _prototypes) { TabPage page = new TabPage(p.Name); page.BackColor = SystemColors.Window; page.Paint += new PaintEventHandler(OnPaintPage); StrokeTabs.TabPages.Add(page); } int tabWidth = 0; for (int i = 0; i < StrokeTabs.TabCount; i++) { Rectangle r = StrokeTabs.GetTabRect(i); tabWidth += r.Width; } this.Width = Math.Max(Width, Math.Min(Screen.PrimaryScreen.WorkingArea.Width / 2, tabWidth + 20)); } }
/// ----------------------------------------------------------------------------------- /// <summary> /// /// </summary> /// ----------------------------------------------------------------------------------- protected override void OnLoad(EventArgs e) { base.OnLoad(e); // If not in the design mode, then move the tab control up so the tabs disappear. // Do this because we really don't want the tab control to act like a tab control. // We just want the ability to have multiple pages without the ability to get to // those pages via the tabs across the top. if (!DesignMode) { if (tabSteps.TabCount > 0) { tabSteps.Top = -tabSteps.GetTabRect(0).Height; tabSteps.Height += tabSteps.GetTabRect(0).Height; m_CurrentStepNumber = 0; tabSteps.SelectedTab = tabSteps.TabPages[0]; UpdateStepLabel(); } m_btnBack.Enabled = false; } }
// show context menu for tab headers private void tabControl1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Right) { for (int intI = 1; intI < tabControl1.TabCount; intI++) { Rectangle rt = tabControl1.GetTabRect(intI); if (e.X > rt.Left && e.X < rt.Right && e.Y > rt.Top && e.Y < rt.Bottom) { this.contextMenu1.Show(this.tabControl1, new Point(e.X, e.Y)); } } } }
private void tabControl_MouseUp(object sender, MouseEventArgs e) { for (int i = 0; i < this.tabControl.TabPages.Count; i++) { Rectangle r = tabControl.GetTabRect(i); //Getting the position of the "x" mark. Rectangle closeButton = new Rectangle(r.Right - 15, r.Top + 4, 9, 7); if (closeButton.Contains(e.Location)) { this.tabControl.SelectedIndex = i; try { CloseProject(); } catch (CancelException) { //no action } return; } } }
public static void tabProc_MouseDown(int SelectedProcTab,ODGrid gridProg,TabControl tabProc,Size ClientSize,MouseEventArgs e) { if(Programs.UsingOrion) { return;//tabs never minimize } //selected tab will have changed, so we need to test the original selected tab: Rectangle rect=tabProc.GetTabRect(SelectedProcTab); if(rect.Contains(e.X,e.Y) && tabProc.Height>27) {//clicked on the already selected tab which was maximized tabProc.Height=27; tabProc.Refresh(); gridProg.Location=new Point(tabProc.Left,tabProc.Bottom+1); gridProg.Height=ClientSize.Height-gridProg.Location.Y-2; } else if(tabProc.Height==27) {//clicked on a minimized tab tabProc.Height=259; tabProc.Refresh(); gridProg.Location=new Point(tabProc.Left,tabProc.Bottom+1); gridProg.Height=ClientSize.Height-gridProg.Location.Y-2; } else {//clicked on a new tab //height will have already been set, so do nothing } SelectedProcTab=tabProc.SelectedIndex; }
private TabPage TabAtPoint(TabControl tabCtrl, Point location) { for (int i = 0; i < tabCtrl.TabCount; i++) { Rectangle r = tabCtrl.GetTabRect(i); if (r.Contains(location)) { return tabCtrl.TabPages[i]; } } return null; }
public void ux_tabcontrolMouseDownEvent(TabControl ux_tabcontrolDataview, MouseEventArgs e) { int clickedTabPage = ux_tabcontrolDataview.SelectedIndex; // Attempt to find the tabpage that was clicked... for (int i = 0; i < ux_tabcontrolDataview.TabPages.Count; i++) { if (ux_tabcontrolDataview.GetTabRect(i).Contains(e.Location)) clickedTabPage = i; //MessageBox.Show(ux_tabcontrolDataview.TabPages[i].Text + " : " + e.Location.ToString()); } if (e.Button == MouseButtons.Left) { // Begin tabpage drag and drop move (if the clicked tab is not // the "ux_tabpageDataviewNewTab" tabpage - which is use to add new dataviews)... if (ux_tabcontrolDataview.TabPages[clickedTabPage] != ux_tabcontrolDataview.TabPages["ux_tabpageDataviewNewTab"]) { ux_tabcontrolDataview.DoDragDrop(ux_tabcontrolDataview.TabPages[clickedTabPage], DragDropEffects.Move); } } else if (e.Button == MouseButtons.Right) { // Make the right clicked tabpage the selected tabpage for the control... ux_tabcontrolDataview.SelectTab(clickedTabPage); } }
public void ux_tabcontrolDragOverEvent(TabControl ux_tabcontrolDataview, DragEventArgs e) { // Convert the mouse coordinates from screen to client... System.Drawing.Point ptClientCoord = ux_tabcontrolDataview.PointToClient(new System.Drawing.Point(e.X, e.Y)); //int destinationTabPage = ux_tabcontrolDataview.TabPages.IndexOf((TabPage)e.Data.GetData(typeof(TabPage))); if (e.Data.GetDataPresent("System.Windows.Forms.TabPage")) { int destinationTabPage = ux_tabcontrolDataview.TabPages.IndexOf((TabPage)e.Data.GetData("System.Windows.Forms.TabPage")); // Attempt to find the tabpage that is being dragged over... for (int i = 0; i < ux_tabcontrolDataview.TabPages.Count; i++) { if (ux_tabcontrolDataview.GetTabRect(i).Contains(ptClientCoord)) destinationTabPage = i; } ////if (e.Data.GetDataPresent(typeof(TabPage)) && //if (e.Data.GetDataPresent("System.Windows.Forms.TabPage") && ////ux_tabcontrolDataview.TabPages[destinationTabPage] != (TabPage)e.Data.GetData(typeof(TabPage)) /* && //ux_tabcontrolDataview.TabPages[destinationTabPage] != (TabPage)e.Data.GetData("System.Windows.Forms.TabPage") /* && // destinationTabPage != ux_tabcontrolDataview.TabPages.IndexOfKey("ux_tabpageDataviewNewTab")*/ // ) if (ux_tabcontrolDataview.TabPages[destinationTabPage] != (TabPage)e.Data.GetData(typeof(TabPage))) { e.Effect = DragDropEffects.Move; } else { e.Effect = DragDropEffects.None; } } }
public void ux_tabcontrolDragDropEvent(TabControl ux_tabcontrolDataview, DragEventArgs e) { if (e.AllowedEffect == e.Effect) { // Convert the mouse coordinates from screen to client... System.Drawing.Point ptClientCoord = ux_tabcontrolDataview.PointToClient(new System.Drawing.Point(e.X, e.Y)); int destinationTabPageIndex = -1; int originalTabPageIndex = -1; // Attempt to find where the tabpage should be dropped... for (int i = 0; i < ux_tabcontrolDataview.TabPages.Count; i++) { //if (ux_tabcontrolDataview.TabPages[i] == e.Data.GetData(typeof(TabPage))) originalTabPageIndex = i; if (ux_tabcontrolDataview.TabPages[i] == e.Data.GetData("System.Windows.Forms.TabPage")) originalTabPageIndex = i; if (ux_tabcontrolDataview.GetTabRect(i).Contains(ptClientCoord)) destinationTabPageIndex = i; } // Now create a copy of the tabpage that is being moved so that // you can remove the orginal and insert the copy at the right spot... TabPage newTabPage = new TabPage(); //newTabPage.Text = ((TabPage)e.Data.GetData(typeof(TabPage))).Text; newTabPage.Text = ((TabPage)e.Data.GetData("System.Windows.Forms.TabPage")).Text; //newTabPage.Tag = ((TabPage)e.Data.GetData(typeof(TabPage))).Tag; newTabPage.Tag = ((TabPage)e.Data.GetData("System.Windows.Forms.TabPage")).Tag; ux_tabcontrolDataview.TabPages.Insert(destinationTabPageIndex, newTabPage); ux_tabcontrolDataview.SelectTab(destinationTabPageIndex); if (originalTabPageIndex < destinationTabPageIndex) { ux_tabcontrolDataview.TabPages.RemoveAt(originalTabPageIndex); } else { ux_tabcontrolDataview.TabPages.RemoveAt(originalTabPageIndex + 1); } } }
private int getHoverTabIndex(TabControl tc) { for (int i = 0; i < tc.TabPages.Count; i++) { if (tc.GetTabRect(i).Contains(tc.PointToClient(Cursor.Position))) return i; } return -1; }
public override void DrawTabControl( Graphics dc, Rectangle area, TabControl tab ) { // Do we need to fill the back color? It can't be changed... dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), area ); Rectangle panel_rect = TabControlGetPanelRect( tab ); if ( tab.Appearance == TabAppearance.Normal ) { CPDrawBorder( dc, panel_rect, BorderColor, 1, ButtonBorderStyle.Solid, BorderColor, 1, ButtonBorderStyle.Solid, BorderColor, 1, ButtonBorderStyle.Solid, BorderColor, 1, ButtonBorderStyle.Solid ); } if ( tab.Alignment == TabAlignment.Top ) { for ( int r = tab.TabPages.Count; r > 0; r-- ) { for ( int i = tab.SliderPos; i < tab.TabPages.Count; i++ ) { if ( i == tab.SelectedIndex ) continue; if ( r != tab.TabPages[ i ].Row ) continue; Rectangle rect = tab.GetTabRect( i ); if ( !rect.IntersectsWith( area ) ) continue; DrawTab( dc, tab.TabPages[ i ], tab, rect, false ); } } } else { for ( int r = 0; r < tab.TabPages.Count; r++ ) { for ( int i = tab.SliderPos; i < tab.TabPages.Count; i++ ) { if ( i == tab.SelectedIndex ) continue; if ( r != tab.TabPages[ i ].Row ) continue; Rectangle rect = tab.GetTabRect( i ); if ( !rect.IntersectsWith( area ) ) continue; DrawTab( dc, tab.TabPages[ i ], tab, rect, false ); } } } if ( tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos ) { Rectangle rect = tab.GetTabRect( tab.SelectedIndex ); if ( rect.IntersectsWith( area ) ) DrawTab( dc, tab.TabPages[ tab.SelectedIndex ], tab, rect, true ); } if ( tab.ShowSlider ) { Rectangle right = TabControlGetRightScrollRect( tab ); Rectangle left = TabControlGetLeftScrollRect( tab ); CPDrawScrollButton( dc, right, ScrollButton.Right, tab.RightSliderState ); CPDrawScrollButton( dc, left, ScrollButton.Left, tab.LeftSliderState ); } }
public virtual void Draw (Graphics dc, Rectangle area, TabControl tab) { DrawBackground (dc, area, tab); int start = 0; int end = tab.TabPages.Count; int delta = 1; if (tab.Alignment == TabAlignment.Top) { start = end; end = 0; delta = -1; } if (tab.SizeMode == TabSizeMode.Fixed) defaultFormatting.Alignment = StringAlignment.Center; else defaultFormatting.Alignment = StringAlignment.Near; int counter = start; for (; counter != end; counter += delta) { for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) { if (i == tab.SelectedIndex) continue; if (counter != tab.TabPages[i].Row) continue; Rectangle rect = tab.GetTabRect (i); if (!rect.IntersectsWith (area)) continue; DrawTab (dc, tab.TabPages[i], tab, rect, false); } } if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) { Rectangle rect = tab.GetTabRect (tab.SelectedIndex); if (rect.IntersectsWith (area)) DrawTab (dc, tab.TabPages[tab.SelectedIndex], tab, rect, true); } if (tab.ShowSlider) { Rectangle right = GetRightScrollRect (tab); Rectangle left = GetLeftScrollRect (tab); DrawScrollButton (dc, right, area, ScrollButton.Right, tab.RightSliderState); DrawScrollButton (dc, left, area, ScrollButton.Left, tab.LeftSliderState); } }
// FIXME: regions near the borders don't get filled with the correct backcolor // TODO: TabAlignment.Left and TabAlignment.Bottom public override void DrawTabControl( Graphics dc, Rectangle area, TabControl tab ) { if (tab.Parent != null) dc.FillRectangle( ResPool.GetSolidBrush( tab.Parent.BackColor ), area ); else dc.FillRectangle( ResPool.GetSolidBrush( tab.BackColor ), area ); Rectangle panel_rect = TabControlGetPanelRect( tab ); if ( tab.Appearance == TabAppearance.Normal ) { switch ( tab.Alignment ) { case TabAlignment.Top: // inner border... Pen pen = ResPool.GetPen( Color.White ); dc.DrawLine( pen, panel_rect.Left + 1, panel_rect.Top, panel_rect.Left + 1, panel_rect.Bottom - 1 ); dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top , panel_rect.Right - 2, panel_rect.Top ); pen = ResPool.GetPen( tab_inner_border_color ); dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Top + 1, panel_rect.Right - 2, panel_rect.Bottom - 2 ); dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Bottom - 1, panel_rect.Left + 2, panel_rect.Bottom - 1 ); // border pen = ResPool.GetPen( tab_border_color ); dc.DrawLine( pen, panel_rect.Left, panel_rect.Top - 1, panel_rect.Right - 1, panel_rect.Top - 1 ); dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Top - 1, panel_rect.Right - 1, panel_rect.Bottom - 2 ); dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Bottom - 2, panel_rect.Right - 3, panel_rect.Bottom ); dc.DrawLine( pen, panel_rect.Right - 3, panel_rect.Bottom, panel_rect.Left + 2, panel_rect.Bottom ); dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Bottom, panel_rect.Left, panel_rect.Bottom - 2 ); dc.DrawLine( pen, panel_rect.Left, panel_rect.Bottom - 2, panel_rect.Left, panel_rect.Top - 1 ); break; // FIXME: the size of the tab page is to big to draw the upper inner white border case TabAlignment.Right: // inner border... pen = ResPool.GetPen( Color.White ); dc.DrawLine( pen, panel_rect.Left + 1, panel_rect.Top + 1, panel_rect.Left + 1, panel_rect.Bottom - 1 ); dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top + 1 , panel_rect.Right - 2, panel_rect.Top + 1 ); pen = ResPool.GetPen( tab_inner_border_color ); dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Top + 1, panel_rect.Right - 2, panel_rect.Bottom - 2 ); dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Bottom - 1, panel_rect.Left + 2, panel_rect.Bottom - 1 ); // border pen = ResPool.GetPen( tab_border_color ); dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top, panel_rect.Right - 1, panel_rect.Top ); dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Top, panel_rect.Right - 1, panel_rect.Bottom ); dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Bottom, panel_rect.Left + 2, panel_rect.Bottom ); dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Bottom, panel_rect.Left, panel_rect.Bottom - 2 ); dc.DrawLine( pen, panel_rect.Left, panel_rect.Bottom - 2, panel_rect.Left, panel_rect.Top + 2 ); dc.DrawLine( pen, panel_rect.Left, panel_rect.Top + 2, panel_rect.Left + 2, panel_rect.Top ); break; } } if (tab.Alignment == TabAlignment.Top) { for (int r = tab.TabPages.Count; r > 0; r--) { for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) { if (i == tab.SelectedIndex) continue; if (r != tab.TabPages [i].Row) continue; Rectangle rect = tab.GetTabRect (i); if (!rect.IntersectsWith (area)) continue; DrawTab (dc, tab.TabPages [i], tab, rect, false); } } } else { for (int r = 0; r < tab.TabPages.Count; r++) { for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) { if (i == tab.SelectedIndex) continue; if (r != tab.TabPages [i].Row) continue; Rectangle rect = tab.GetTabRect (i); if (!rect.IntersectsWith (area)) continue; DrawTab (dc, tab.TabPages [i], tab, rect, false); } } } if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) { Rectangle rect = tab.GetTabRect (tab.SelectedIndex); if (rect.IntersectsWith (area)) DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true); } if (tab.ShowSlider) { Rectangle right = TabControlGetRightScrollRect (tab); Rectangle left = TabControlGetLeftScrollRect (tab); CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState); CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState); } }
public void GetTabRectTest () { TabControl myTabControl = new TabControl (); TabPage myTabPage = new TabPage(); myTabControl.Controls.Add(myTabPage); myTabPage.TabIndex = 0; Rectangle myTabRect = myTabControl.GetTabRect (0); Assert.AreEqual (2, myTabRect.X, "#GetT1"); Assert.AreEqual (2, myTabRect.Y, "#GetT2"); Assert.AreEqual (42, myTabRect.Width, "#GetT3"); // It is environment dependent //Assert.AreEqual (18, myTabRect.Height, "#GetT4"); }
private void DrawTabControlTabs(TabControl tabControl, DrawItemEventArgs e, ImageList images) { // Get the bounding end of tab strip rectangles. var tabstripEndRect = tabControl.GetTabRect(tabControl.TabPages.Count - 1); var tabstripEndRectF = new RectangleF(tabstripEndRect.X + tabstripEndRect.Width, tabstripEndRect.Y - 5, tabControl.Width - (tabstripEndRect.X + tabstripEndRect.Width), tabstripEndRect.Height + 5); var leftVerticalLineRect = new RectangleF(2, tabstripEndRect.Y + tabstripEndRect.Height + 2, 2, tabControl.TabPages[tabControl.SelectedIndex].Height + 2); var rightVerticalLineRect = new RectangleF(tabControl.TabPages[tabControl.SelectedIndex].Width + 4, tabstripEndRect.Y + tabstripEndRect.Height + 2, 2, tabControl.TabPages[tabControl.SelectedIndex].Height + 2); var bottomHorizontalLineRect = new RectangleF(2, tabstripEndRect.Y + tabstripEndRect.Height + tabControl.TabPages[tabControl.SelectedIndex].Height + 2, tabControl.TabPages[tabControl.SelectedIndex].Width + 4, 2); RectangleF leftVerticalBarNearFirstTab = new Rectangle(0, 0, 2, tabstripEndRect.Height + 2); // First, do the end of the tab strip. // If we have an image use it. if (tabControl.Parent.BackgroundImage != null) { var src = new RectangleF(tabstripEndRectF.X + tabControl.Left, tabstripEndRectF.Y + tabControl.Top, tabstripEndRectF.Width, tabstripEndRectF.Height); e.Graphics.DrawImage(tabControl.Parent.BackgroundImage, tabstripEndRectF, src, GraphicsUnit.Pixel); } // If we have no image, use the background color. else { using (var backBrush = new SolidBrush(tabControl.Parent.BackColor)) { e.Graphics.FillRectangle(backBrush, tabstripEndRectF); e.Graphics.FillRectangle(backBrush, leftVerticalLineRect); e.Graphics.FillRectangle(backBrush, rightVerticalLineRect); e.Graphics.FillRectangle(backBrush, bottomHorizontalLineRect); if (mainTabControl.SelectedIndex != 0) { e.Graphics.FillRectangle(backBrush, leftVerticalBarNearFirstTab); } } } // Set up the page and the various pieces. var page = tabControl.TabPages[e.Index]; using (var backBrush = new SolidBrush(page.BackColor)) { using (var foreBrush = new SolidBrush(page.ForeColor)) { var tabName = page.Text; // Set up the offset for an icon, the bounding rectangle and image size and then fill the background. var iconOffset = 0; Rectangle tabBackgroundRect; if (e.Index == mainTabControl.SelectedIndex) { tabBackgroundRect = e.Bounds; e.Graphics.FillRectangle(backBrush, tabBackgroundRect); } else { tabBackgroundRect = new Rectangle(e.Bounds.X, e.Bounds.Y - 2, e.Bounds.Width, e.Bounds.Height + 4); e.Graphics.FillRectangle(backBrush, tabBackgroundRect); var rect = new Rectangle(e.Bounds.X - 2, e.Bounds.Y - 2, 1, 2); e.Graphics.FillRectangle(backBrush, rect); rect = new Rectangle(e.Bounds.X - 1, e.Bounds.Y - 2, 1, 2); e.Graphics.FillRectangle(backBrush, rect); rect = new Rectangle(e.Bounds.X + e.Bounds.Width, e.Bounds.Y - 2, 1, 2); e.Graphics.FillRectangle(backBrush, rect); rect = new Rectangle(e.Bounds.X + e.Bounds.Width + 1, e.Bounds.Y - 2, 1, 2); e.Graphics.FillRectangle(backBrush, rect); } // If we have images, process them. if (images != null) { // Get sice and image. var size = images.ImageSize; Image icon = null; if (page.ImageIndex > -1) icon = images.Images[page.ImageIndex]; else if (page.ImageKey != "") icon = images.Images[page.ImageKey]; // If there is an image, use it. if (icon != null) { var startPoint = new Point(tabBackgroundRect.X + 2 + ((tabBackgroundRect.Height - size.Height) / 2), tabBackgroundRect.Y + 2 + ((tabBackgroundRect.Height - size.Height) / 2)); e.Graphics.DrawImage(icon, new Rectangle(startPoint, size)); iconOffset = size.Width + 4; } } // Draw out the label. var labelRect = new Rectangle(tabBackgroundRect.X + iconOffset, tabBackgroundRect.Y + 5, tabBackgroundRect.Width - iconOffset, tabBackgroundRect.Height - 3); using (var sf = new StringFormat { Alignment = StringAlignment.Center }) { e.Graphics.DrawString(tabName, new Font(e.Font.FontFamily, 8.25F, e.Font.Style), foreBrush, labelRect, sf); } } } }
private TabPage GetPageByPoint(TabControl tabControl, Point point) { for (int i = 0; i < tabControl.TabPages.Count; i++) { TabPage page = tabControl.TabPages[i]; if (tabControl.GetTabRect(i).Contains(point)) return page; } return null; }