/// <summary> /// Override the normal drawing of the tabs /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="drawItemInfo"> /// The draw item info. /// </param> private void TabControlAdv1DrawItem(object sender, DrawTabEventArgs drawItemInfo) { drawItemInfo.DrawBackground(); drawItemInfo.DrawInterior(); var rectTab = drawItemInfo.Bounds; var g = drawItemInfo.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; // Create a path for the border var gp = new GraphicsPath(); gp.AddBezier( rectTab.Right - 1, rectTab.Bottom + 6, rectTab.Right - 1, rectTab.Bottom + 2, rectTab.Left, rectTab.Bottom - 3, rectTab.Left, rectTab.Bottom - 7); gp.AddLine(rectTab.Left, rectTab.Bottom - 4, rectTab.Left, rectTab.Top + 5); Point[] curvePoints1 = { new Point(rectTab.Left, rectTab.Top + 5), new Point(rectTab.Left + 2, rectTab.Top + 2), new Point(rectTab.Left + 3, rectTab.Top + 1), new Point(rectTab.Left + 5, rectTab.Top) }; gp.AddCurve(curvePoints1); gp.AddBezier(curvePoints1[0], curvePoints1[1], curvePoints1[2], curvePoints1[3]); gp.AddLine(curvePoints1[3], new Point(rectTab.Right - 6, rectTab.Top)); Point[] curvePoints2 = { new Point(rectTab.Right - 6, rectTab.Top), new Point(rectTab.Right - 2, rectTab.Top - 1), new Point(rectTab.Right - 2, rectTab.Top - 3), new Point(rectTab.Right - 1, rectTab.Top - 5) }; gp.AddCurve(curvePoints2); if (((int)drawItemInfo.State & (int)DrawItemState.Selected) > 0) { g.FillPath(new SolidBrush(drawItemInfo.BackColor), gp); drawItemInfo.DrawInterior(); } else { // Draw the Text and Image first drawItemInfo.DrawInterior(); // Then alpha blend active tab color over it g.FillPath(new SolidBrush(Color.FromArgb(128, this.tabControlAdv1.ActiveTabColor)), gp); } }
private void DrawItems(object sender, DrawTabEventArgs drawItemInfo) { using var gp = new GraphicsPath(); using var sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; drawItemInfo.Graphics.SmoothingMode = SmoothingMode.HighQuality; drawItemInfo.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; float fontSize; Rectangle interiorBounds; Rectangle tabBounds; if (drawItemInfo.State == DrawItemState.Selected) { using Pen outline = new Pen(ActiveTabOutlineColor, ActiveTabOutlineWidth) { LineJoin = LineJoin.Round }; using Brush foreBrush = new SolidBrush(SelectedTab.ForeColor); Text = SelectedTab.Text; interiorBounds = drawItemInfo.BoundsInterior; interiorBounds.Width += TabGap; fontSize = NewFontSize(drawItemInfo.Graphics, drawItemInfo.BoundsInterior.Size, ActiveTabFont, Text); tabBounds = drawItemInfo.Bounds; tabBounds.Width += TabGap; drawItemInfo.Graphics.FillRectangle(new SolidBrush(ActiveTabColor), tabBounds); gp.AddString(Text, ActiveTabFont.FontFamily, (int)ActiveTabFont.Style, fontSize * 1.1f, interiorBounds, sf); if (EnableOutline) { drawItemInfo.Graphics.DrawPath(outline, gp); } drawItemInfo.Graphics.FillPath(foreBrush, gp); } else { using Pen outline = new Pen(InactiveTabOutlineColor, InactiveTabOutlineWidth) { LineJoin = LineJoin.Round }; using Brush foreBrush = new SolidBrush(TabPages[drawItemInfo.Index].ForeColor); Text = TabPages[drawItemInfo.Index].Text; interiorBounds = drawItemInfo.BoundsInterior; interiorBounds.Width += TabGap; fontSize = NewFontSize(drawItemInfo.Graphics, drawItemInfo.BoundsInterior.Size, Font, Text); tabBounds = drawItemInfo.Bounds; tabBounds.Width += TabGap; drawItemInfo.Graphics.FillRectangle(new SolidBrush(InactiveTabColor), tabBounds); gp.AddString(Text, Font.FontFamily, (int)Font.Style, fontSize * 1.1f, interiorBounds, sf); if (EnableOutline) { drawItemInfo.Graphics.DrawPath(outline, gp); } drawItemInfo.Graphics.FillPath(foreBrush, gp); } }