自定义Tab
Code
protected void DrawTabStrip(Graphics g)
{
Rectangle rectTabStrip = ClientRectangle;
foreach (Tab tab in Tabs)
{
if (Tabs.IndexOf(tab) == index)
{
continue;
}
else
DrawTab(g,tab,GetRectangle(tab));
}
g.DrawLine(PenDocumentTabActiveBorder, rectTabStrip.Left, rectTabStrip.Bottom - 1,
rectTabStrip.Right, rectTabStrip.Bottom - 1);
DrawTab(g, Tabs[index], GetRectangle(Tabs[index]));
}
protected void DrawTabStrip(Graphics g)
{
Rectangle rectTabStrip = ClientRectangle;
foreach (Tab tab in Tabs)
{
if (Tabs.IndexOf(tab) == index)
{
continue;
}
else
DrawTab(g,tab,GetRectangle(tab));
}
g.DrawLine(PenDocumentTabActiveBorder, rectTabStrip.Left, rectTabStrip.Bottom - 1,
rectTabStrip.Right, rectTabStrip.Bottom - 1);
DrawTab(g, Tabs[index], GetRectangle(Tabs[index]));
}
Code
protected void DrawTab(Graphics g,Tab tab,Rectangle rect)
{
GraphicsPath path=GetTabOutline(rect, tab);
if (Tabs.IndexOf(tab) == index)
{
g.FillPath(BrushDocumentActiveBackground, path);
g.DrawPath(PenDocumentTabActiveBorder, path);
}
else
{
g.FillPath(new LinearGradientBrush(rect, SystemColors.ControlLightLight, SystemColors.ControlDark, LinearGradientMode.Vertical), path);
g.DrawPath(PenDocumentTabInactiveBorder, path);
}
TextRenderer.DrawText(g, tab.Text, Font, rect, ColorDocumentInactiveText, DocumentTextFormat);
}
protected void DrawTab(Graphics g,Tab tab,Rectangle rect)
{
GraphicsPath path=GetTabOutline(rect, tab);
if (Tabs.IndexOf(tab) == index)
{
g.FillPath(BrushDocumentActiveBackground, path);
g.DrawPath(PenDocumentTabActiveBorder, path);
}
else
{
g.FillPath(new LinearGradientBrush(rect, SystemColors.ControlLightLight, SystemColors.ControlDark, LinearGradientMode.Vertical), path);
g.DrawPath(PenDocumentTabInactiveBorder, path);
}
TextRenderer.DrawText(g, tab.Text, Font, rect, ColorDocumentInactiveText, DocumentTextFormat);
}
Code
protected GraphicsPath GetTabOutline(Rectangle rect, Tab tab)
{
int curveSize = 6;
GraphicsPath path = new GraphicsPath();
if (Tabs.IndexOf(tab) == index || Tabs.IndexOf(tab) == 0)
{
path.AddLine(rect.Left, rect.Bottom, rect.Left - rect.Height / 2, rect.Bottom);
path.AddLine(rect.Left - rect.Height / 2, rect.Bottom, rect.Left + rect.Height / 2 - curveSize / 2, rect.Top + curveSize / 2);
}
else
{
path.AddLine(rect.Left, rect.Bottom, rect.Left, rect.Bottom - rect.Height / 2);
path.AddLine(rect.Left, rect.Bottom - rect.Height / 2, rect.Left + rect.Height / 2 - curveSize / 2, rect.Top + curveSize / 2);
}
path.AddLine(rect.Left + rect.Height / 2 + curveSize / 2, rect.Top, rect.Right - curveSize / 2, rect.Top);
path.AddArc(new Rectangle(rect.Right - curveSize, rect.Top, curveSize, curveSize), -90, 90);
path.AddLine(rect.Right, rect.Top + curveSize / 2, rect.Right, rect.Bottom);
return path;
}
protected GraphicsPath GetTabOutline(Rectangle rect, Tab tab)
{
int curveSize = 6;
GraphicsPath path = new GraphicsPath();
if (Tabs.IndexOf(tab) == index || Tabs.IndexOf(tab) == 0)
{
path.AddLine(rect.Left, rect.Bottom, rect.Left - rect.Height / 2, rect.Bottom);
path.AddLine(rect.Left - rect.Height / 2, rect.Bottom, rect.Left + rect.Height / 2 - curveSize / 2, rect.Top + curveSize / 2);
}
else
{
path.AddLine(rect.Left, rect.Bottom, rect.Left, rect.Bottom - rect.Height / 2);
path.AddLine(rect.Left, rect.Bottom - rect.Height / 2, rect.Left + rect.Height / 2 - curveSize / 2, rect.Top + curveSize / 2);
}
path.AddLine(rect.Left + rect.Height / 2 + curveSize / 2, rect.Top, rect.Right - curveSize / 2, rect.Top);
path.AddArc(new Rectangle(rect.Right - curveSize, rect.Top, curveSize, curveSize), -90, 90);
path.AddLine(rect.Right, rect.Top + curveSize / 2, rect.Right, rect.Bottom);
return path;
}