Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Drawing.Drawing2D;
- public class DotNetBarTabcontrol : TabControl
- {
- public DotNetBarTabcontrol()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint, true);
- SetStyle(ControlStyles.ResizeRedraw, true);
- SetStyle(ControlStyles.UserPaint, true);
- SetStyle(ControlStyles.DoubleBuffer, true);
- DoubleBuffered = true;
- SizeMode = TabSizeMode.Fixed;
- ItemSize = new Size(44, 136);
- }
- protected override void CreateHandle()
- {
- base.CreateHandle();
- Alignment = TabAlignment.Left;
- }
- Pen ToPen(Color color)
- {
- return new Pen(color);
- }
- Brush ToBrush(Color color)
- {
- return new SolidBrush(color);
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- Bitmap B = new Bitmap(Width, Height);
- Graphics G = Graphics.FromImage(B);
- try
- {
- SelectedTab.BackColor = Color.White;
- } catch { }
- G.Clear(Color.White);
- StringFormat sf = new StringFormat();
- sf.Alignment = StringAlignment.Center;
- sf.LineAlignment = StringAlignment.Center;
- G.FillRectangle(new SolidBrush(Color.FromArgb(218, 231, 244)), new Rectangle(0, 0, (ItemSize.Height + 4), Height));
- G.DrawLine(new Pen(Color.FromArgb(170, 187, 204)), new Point((Width - 1), 0), new Point((Width - 1), (Height - 1)));
- // comment out to get rid of the borders
- G.DrawLine(new Pen(Color.FromArgb(170, 187, 204)), new Point((ItemSize.Height + 1), 0), new Point((Width - 1), 0));
- // comment out to get rid of the borders
- G.DrawLine(new Pen(Color.FromArgb(170, 187, 204)), new Point((ItemSize.Height + 3), (Height - 1)), new Point((Width - 1), (Height - 1)));
- // comment out to get rid of the borders
- G.DrawLine(new Pen(Color.FromArgb(170, 187, 204)), new Point((ItemSize.Height + 3), 0), new Point((ItemSize.Height + 3), 999));
- for (int i = 0; (i <= (TabCount - 1)); i++)
- {
- if ((i == SelectedIndex))
- {
- Rectangle x2 = new Rectangle(new Point((GetTabRect(i).Location.X - 2), (GetTabRect(i).Location.Y - 2)), new Size((GetTabRect(i).Width + 3), (GetTabRect(i).Height - 1)));
- ColorBlend myBlend = new ColorBlend();
- myBlend.Colors = new Color[] { Color.FromArgb(38, 102, 192), Color.FromArgb(71, 134, 220), Color.FromArgb(38, 102, 192) };
- myBlend.Positions = new float[] { 0.0F, 0.5F, 1.0F};
- LinearGradientBrush lgBrush = new LinearGradientBrush(x2, Color.Black, Color.Black, 90.0F);
- lgBrush.InterpolationColors = myBlend;
- G.FillRectangle(lgBrush, x2);
- G.DrawRectangle(new Pen(Color.FromArgb(12, 63, 149)), x2);
- G.SmoothingMode = SmoothingMode.HighQuality;
- Point[] p = new Point[] { new Point((ItemSize.Height - 3), (GetTabRect(i).Location.Y + 20)), new Point((ItemSize.Height + 4), (GetTabRect(i).Location.Y + 14)), new Point((ItemSize.Height + 4), (GetTabRect(i).Location.Y + 27)) };
- G.FillPolygon(Brushes.White, p);
- if (ImageList != null)
- {
- try
- {
- if (ImageList.Images[TabPages[i].ImageIndex] != null)
- {
- G.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point((x2.Location.X + 8), (x2.Location.Y + 6)));
- G.DrawString((" " + TabPages[i].Text), new Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, x2, sf);
- }
- else
- {
- G.DrawString(TabPages[i].Text, new Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, x2, sf);
- }
- }
- catch
- {
- G.DrawString(TabPages[i].Text, new Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, x2, sf);
- }
- }
- else
- {
- G.DrawString(TabPages[i].Text, new Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, x2, sf);
- }
- G.DrawLine(new Pen(Color.FromArgb(200, 200, 250)), new Point((x2.Location.X - 1), (x2.Location.Y - 1)), new Point(x2.Location.X, x2.Location.Y));
- G.DrawLine(new Pen(Color.FromArgb(200, 200, 250)), new Point((x2.Location.X - 1), (x2.Bottom - 1)), new Point(x2.Location.X, x2.Bottom));
- }
- else
- {
- Rectangle x2 = new Rectangle(new Point((GetTabRect(i).Location.X - 2), (GetTabRect(i).Location.Y - 2)), new Size((GetTabRect(i).Width + 3), (GetTabRect(i).Height + 1)));
- G.FillRectangle(new SolidBrush(Color.FromArgb(218, 231, 244)), x2);
- G.DrawLine(new Pen(Color.FromArgb(170, 187, 204)), new Point(x2.Right, x2.Top), new Point(x2.Right, x2.Bottom));
- if (ImageList != null)
- {
- try
- {
- if (ImageList.Images[TabPages[i].ImageIndex] != null)
- {
- G.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point((x2.Location.X + 8), (x2.Location.Y + 6)));
- G.DrawString((" " + TabPages[i].Text), Font, Brushes.Black, x2, sf);
- }
- else
- {
- G.DrawString(TabPages[i].Text, Font, Brushes.Black, x2, sf);
- }
- }
- catch
- {
- G.DrawString(TabPages[i].Text, Font, Brushes.Black, x2, sf);
- }
- }
- else
- {
- G.DrawString(TabPages[i].Text, Font, Brushes.Black, x2, sf);
- }
- }
- }
- e.Graphics.DrawImage(B, 0, 0);
- G.Dispose();
- B.Dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment