private void DrawCustomTabControl(Graphics g, Rectangle clipRect)
{
/* In this method we draw only those parts of the control which intersects with the
* clipping rectangle. It's some kind of optimization.*/
if (!this.Visible) return;
//selected tab index and rectangle
int iSel = this.SelectedIndex;
Rectangle selRect = iSel != -1 ? this.GetTabRect(iSel) : Rectangle.Empty;
Rectangle rcPage = this.ClientRectangle;
//correcting page rectangle
switch (this.Alignment)
{
case TabAlignment.Top:
{
int trunc = selRect.Height * this.RowCount + 2;
rcPage.Y += trunc; rcPage.Height -= trunc;
} break;
case TabAlignment.Bottom: rcPage.Height -= (selRect.Height + VSTabControl.sAdjHeight) * this.RowCount; break;
}
//draw page itself
if (rcPage.IntersectsWith(clipRect)) TabRenderer.DrawTabPage(g, rcPage);
int tabCount = this.TabCount;
if (tabCount == 0) return;
using (StringFormat textFormat = new StringFormat())
{
textFormat.Alignment = StringAlignment.Center;
textFormat.LineAlignment = StringAlignment.Center;
//drawing unselected tabs
this.lastHotIndex = HitTest();//hot tab
for (int iTab = 0; iTab < tabCount; iTab++)
if (iTab != iSel)
{
Rectangle tabRect = this.GetTabRect(iTab);
if (tabRect.Right >= 3 && tabRect.IntersectsWith(clipRect))
{
TabItemState state = iTab == this.lastHotIndex ? TabItemState.Hot : TabItemState.Normal;
DrawTabItem(g, iTab, state, tabRect, textFormat);
}
}
/* Drawing selected tab. We'll also increase selected tab's rectangle. It should be a little
* bigger than other tabs.*/
selRect.Inflate(2, 2);
if (iSel != -1 && selRect.IntersectsWith(clipRect))
DrawTabItem(g, iSel, TabItemState.Selected, selRect, textFormat);
}
}