protected override void OnPaintBackground(PaintEventArgs pevent)
{
// Draw the whole Tab control
//
Graphics g = pevent.Graphics;
Pen borderGray = new Pen(Color.FromArgb(172, 172, 172));
// Draw the Tab Control background stuff
//
g.FillRectangle(Brushes.White, 0, 0, this.Size.Width, this.Size.Height);
g.FillRectangle(SystemBrushes.Control, 0, 0, this.Size.Width, 25);
g.DrawLine(borderGray, new Point(0, 0), new Point(0, this.Height));
g.DrawLine(borderGray, new Point(5, 25), new Point(this.Width, 25));
// Loop through all the tabs & paint them
//
TabPage currTab;
Rectangle TabBoundary, origTabBoundary;
RectangleF TabTextBoundary;
StringFormat format = new StringFormat();
Bitmap image;
for (int i = 0; i < TabPages.Count; i++)
{
currTab = TabPages[i];
TabBoundary = this.GetTabRect(i);
origTabBoundary = TabBoundary;
TabTextBoundary = new RectangleF(TabBoundary.X + 12, TabBoundary.Y + 3, TabBoundary.Width, TabBoundary.Height);
if (currTab == SelectedTab)
{
// Fill Background
TabBoundary = new Rectangle(TabBoundary.X - 2, TabBoundary.Y - 2, TabBoundary.Width + 2, TabBoundary.Height + 4);
g.FillRectangle(new SolidBrush(Color.White), TabBoundary);
// Draw Border
g.DrawLine(borderGray, TabBoundary.Location, new Point(TabBoundary.X, TabBoundary.Height));
g.DrawLine(borderGray, TabBoundary.Location, new Point(TabBoundary.Right, TabBoundary.Y));
g.DrawLine(borderGray, new Point(TabBoundary.Right, TabBoundary.Y), new Point(TabBoundary.Right, TabBoundary.Bottom));
}
else
{
// Fill Background
TabBoundary = new Rectangle(TabBoundary.X + 2, TabBoundary.Y + 2, TabBoundary.Width, TabBoundary.Height);
g.FillRectangle(new LinearGradientBrush(TabBoundary, SystemColors.Control, SystemColors.ControlLight, 90.0f), TabBoundary);
// Draw Border
TabBoundary = new Rectangle(TabBoundary.X - 1, TabBoundary.Y - 1, TabBoundary.Width - 1, TabBoundary.Height);
g.DrawRectangle(borderGray, TabBoundary);
}
// Draw Tab Title
//
Font f = new System.Drawing.Font("Segoe UI", 10.0f);
g.DrawString(currTab.Text, f, new SolidBrush(Color.Black), TabTextBoundary, format);
// Draw Tab Close Button
//
if (ImageList.Images.Count > 0)
{
if (currTab.ImageIndex == -1) currTab.ImageIndex = 0;// Sometimes ImageIndex is not set yet
// Zet de kleur wit om naar transparency
//
image = (Bitmap)ImageList.Images[currTab.ImageIndex];
image.MakeTransparent();
g.DrawImage(image, origTabBoundary.Right - 15, origTabBoundary.Top + 5, image.Width, image.Height);
}
}
}