private static int GetTabRow(MgTabControl tabControl, int index) { // All calculations will use this rect as the base point // because the itemsize does not return the correct width. Rectangle rect = tabControl.GetTabRect(index); int row = -1; switch (tabControl.Alignment) { case TabAlignment.Top: row = (rect.Y - 2) / rect.Height; break; case TabAlignment.Bottom: row = ((tabControl.Height - rect.Y - 2) / rect.Height) - 1; break; case TabAlignment.Left: row = (rect.X - 2) / rect.Width; break; case TabAlignment.Right: row = ((tabControl.Width - rect.X - 2) / rect.Width) - 1; break; } return(row); }
private static void DrawTabText(MgTabControl tabControl, Graphics graphics, GraphicsPath tabPath, int index) { Rectangle tabBounds = GetTabTextRect(tabControl, tabPath, index); Color textColor; // For selected tab // When 'SelectedTabColor' is set TextColor is SelectedTabFgColor else it is Tab's ForeColor if (tabControl.SelectedIndex == index) { textColor = tabControl.SelectedTabFgColor != Color.Empty ? tabControl.SelectedTabFgColor : tabControl.ForeColor; } else { textColor = tabControl.TitleFgColor; // Text color it is Foreground of Title Color for non selected tabs } int orientation = GetOrientation(tabControl); if (tabControl.RightToLeftLayout) { Rectangle clipRect = tabControl.GetTabRect(index); clipRect.X = tabControl.Width - clipRect.Right; // Set clip so that image is not painted outside tab bounds graphics.SetClip(clipRect); } FontDescription font = new FontDescription(tabControl.Font); ControlRenderer.PrintText(graphics, tabBounds, textColor, font, GetTabText(tabControl, orientation, index), false, ContentAlignment.MiddleCenter, true, false, false, false, (tabControl.RightToLeft == RightToLeft.Yes), false, orientation, true); }
private static void DrawTabPage(MgTabControl tabControl, Graphics graphics, int index) { graphics.SmoothingMode = SmoothingMode.HighSpeed; //if the scroller is visible and the tab is fully placed under it, we don't need to draw such tab // in this case we should only paint the border for selected tab if (!tabControl.TabUpDownRect.IsEmpty && tabControl.GetTabRect(index).X >= tabControl.TabUpDownRect.X) { if (index == tabControl.SelectedIndex) { using (GraphicsPath tabBorderPath = GetTabPageBorder(tabControl, index)) { // Paint the border for selected tab even if it is not visible DrawTabBorder(tabControl, graphics, tabBorderPath, index); } } return; } // Get TabPageBorder using (GraphicsPath tabBorderPath = GetTabPageBorder(tabControl, index)) { // Paint the tab background FillTab(tabControl, graphics, tabBorderPath, index); using (GraphicsPath tabRectPath = tabControl.DisplayStyleProvider.GetTabBorder(index)) { Region originalClipRegion = graphics.Clip; // Set clip so that image is not painted outside tab bounds graphics.SetClip(tabControl.DisplayStyleProvider.GetTabRect(index)); // Draw any image DrawTabImage(tabControl, graphics, tabRectPath, index); // Draw the text DrawTabText(tabControl, graphics, tabRectPath, index); // restore original clip graphics.SetClip(originalClipRegion, CombineMode.Replace); } // Paint the border DrawTabBorder(tabControl, graphics, tabBorderPath, index); // Paint a focus indication tabControl.DisplayStyleProvider.DrawTabFocusIndicator(index, graphics); } }