Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //credits to aeonhack
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- using System.Drawing;
- using System.ComponentModel;
- internal class DotNetBarTabcontrol : TabControl
- {
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
- [DefaultValue(false)]
- private bool _DrawPointer = false;
- public bool DrawPointer
- {
- get
- {
- return _DrawPointer;
- }
- set
- {
- _DrawPointer = value;
- }
- }
- public GraphicsPath RoundRect(Rectangle Rectangle, int Curve)
- {
- GraphicsPath P = new GraphicsPath();
- int ArcRectangleWidth = Curve * 2;
- P.AddArc(new Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180F, 90F);
- P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90F, 90F);
- P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0F, 90F);
- P.AddArc(new Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90F, 90F);
- P.AddLine(new Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), new Point(Rectangle.X, Curve + Rectangle.Y));
- return P;
- }
- public GraphicsPath RoundRect(int X, int Y, int Width, int Height, int Curve)
- {
- Rectangle Rectangle = new Rectangle(X, Y, Width, Height);
- GraphicsPath P = new GraphicsPath();
- int ArcRectangleWidth = Curve * 2;
- P.AddArc(new Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180F, 90F);
- P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90F, 90F);
- P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0F, 90F);
- P.AddArc(new Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90F, 90F);
- P.AddLine(new Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), new Point(Rectangle.X, Curve + Rectangle.Y));
- return P;
- }
- public DotNetBarTabcontrol()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
- DoubleBuffered = true;
- SizeMode = TabSizeMode.Fixed;
- ItemSize = new Size(35, 85);
- }
- protected override void CreateHandle()
- {
- base.CreateHandle();
- Alignment = TabAlignment.Left;
- }
- public Pen ToPen(Color color)
- {
- return new Pen(color);
- }
- public 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(Parent.FindForm().BackColor);
- G.FillRectangle(new SolidBrush(Color.FromArgb(96, 110, 121)), new Rectangle(0, 0, ItemSize.Height + 4, Height));
- for (var i = 0; i < TabCount; 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.FromArgb(96, 110, 121), Color.FromArgb(96, 110, 121), Color.FromArgb(96, 110, 121) };
- myBlend.Positions = new[] { 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(96, 110, 121)), x2);
- Rectangle tabRect = new Rectangle(GetTabRect(i).Location.X + 4, GetTabRect(i).Location.Y + 2, GetTabRect(i).Size.Width + 10, GetTabRect(i).Size.Height - 11);
- G.FillPath(new SolidBrush(Color.FromArgb(80, 90, 100)), RoundRect(tabRect, 5));
- G.DrawPath(new Pen(Color.FromArgb(67, 77, 87)), RoundRect(new Rectangle(tabRect.X + 1, tabRect.Y + 1, tabRect.Width - 1, tabRect.Height - 2), 5));
- G.DrawPath(new Pen(Color.FromArgb(115, 125, 135)), RoundRect(tabRect, 5));
- G.SmoothingMode = SmoothingMode.HighQuality;
- if (_DrawPointer)
- {
- 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);
- Invalidate();
- }
- 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.ToUpper(), new Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, x2, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center });
- }
- else
- {
- G.DrawString(TabPages[i].Text.ToUpper(), new Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, x2, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center });
- }
- }
- catch (Exception ex)
- {
- G.DrawString(TabPages[i].Text.ToUpper(), new Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, x2, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center });
- }
- }
- else
- {
- G.DrawString(TabPages[i].Text.ToUpper(), new Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, x2, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center });
- }
- G.DrawLine(new Pen(Color.FromArgb(96, 110, 121)), new Point(x2.Location.X - 1, x2.Location.Y - 1), new Point(x2.Location.X, x2.Location.Y));
- G.DrawLine(new Pen(Color.FromArgb(96, 110, 121)), 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(96, 110, 121)), x2);
- G.DrawLine(new Pen(Color.FromArgb(96, 110, 121)), 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.White, x2, new StringFormat { LineAlignment = StringAlignment.Near, Alignment = StringAlignment.Near });
- }
- else
- {
- G.DrawString(TabPages[i].Text.ToUpper(), new Font(Font.FontFamily, Font.Size, FontStyle.Bold), new SolidBrush(Color.FromArgb(210, 220, 230)), x2, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center });
- }
- }
- catch (Exception ex)
- {
- G.DrawString(TabPages[i].Text.ToUpper(), new Font(Font.FontFamily, Font.Size, FontStyle.Bold), new SolidBrush(Color.FromArgb(210, 220, 230)), x2, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center });
- }
- }
- else
- {
- G.DrawString(TabPages[i].Text.ToUpper(), new Font(Font.FontFamily, Font.Size, FontStyle.Bold), new SolidBrush(Color.FromArgb(210, 220, 230)), x2, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center });
- }
- }
- G.FillPath(Brushes.White, RoundRect(new Rectangle(86, 0, Width - 89, Height - 3), 5));
- G.DrawPath(new Pen(Color.FromArgb(65, 75, 85)), RoundRect(new Rectangle(86, 0, Width - 89, Height - 3), 5));
- }
- e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
- G.Dispose();
- B.Dispose();
- }
- }
Add Comment
Please, Sign In to add comment