Astekk

Aeonhack's Tab Control Converted to C#

Dec 3rd, 2014
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.58 KB | None | 0 0
  1. //credits to aeonhack
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Drawing.Drawing2D;
  8. using System.Windows.Forms;
  9. using System.Drawing;
  10. using System.ComponentModel;
  11.  
  12.  
  13. internal class DotNetBarTabcontrol : TabControl
  14. {
  15.     [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  16.     [DefaultValue(false)]
  17.     private bool _DrawPointer = false;
  18.     public bool DrawPointer
  19.     {
  20.         get
  21.         {
  22.             return _DrawPointer;
  23.         }
  24.         set
  25.         {
  26.             _DrawPointer = value;
  27.         }
  28.     }
  29.     public GraphicsPath RoundRect(Rectangle Rectangle, int Curve)
  30.     {
  31.         GraphicsPath P = new GraphicsPath();
  32.         int ArcRectangleWidth = Curve * 2;
  33.         P.AddArc(new Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180F, 90F);
  34.         P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90F, 90F);
  35.         P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0F, 90F);
  36.         P.AddArc(new Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90F, 90F);
  37.         P.AddLine(new Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), new Point(Rectangle.X, Curve + Rectangle.Y));
  38.         return P;
  39.     }
  40.     public GraphicsPath RoundRect(int X, int Y, int Width, int Height, int Curve)
  41.     {
  42.         Rectangle Rectangle = new Rectangle(X, Y, Width, Height);
  43.         GraphicsPath P = new GraphicsPath();
  44.         int ArcRectangleWidth = Curve * 2;
  45.         P.AddArc(new Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180F, 90F);
  46.         P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90F, 90F);
  47.         P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0F, 90F);
  48.         P.AddArc(new Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90F, 90F);
  49.         P.AddLine(new Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), new Point(Rectangle.X, Curve + Rectangle.Y));
  50.         return P;
  51.     }
  52.     public DotNetBarTabcontrol()
  53.     {
  54.         SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  55.         DoubleBuffered = true;
  56.         SizeMode = TabSizeMode.Fixed;
  57.         ItemSize = new Size(35, 85);
  58.     }
  59.     protected override void CreateHandle()
  60.     {
  61.         base.CreateHandle();
  62.         Alignment = TabAlignment.Left;
  63.     }
  64.  
  65.     public Pen ToPen(Color color)
  66.     {
  67.         return new Pen(color);
  68.     }
  69.  
  70.     public Brush ToBrush(Color color)
  71.     {
  72.         return new SolidBrush(color);
  73.     }
  74.  
  75.     protected override void OnPaint(PaintEventArgs e)
  76.     {
  77.         Bitmap B = new Bitmap(Width, Height);
  78.         Graphics G = Graphics.FromImage(B);
  79.         try
  80.         {
  81.             SelectedTab.BackColor = Color.White;
  82.         }
  83.         catch
  84.         {
  85.         }
  86.         G.Clear(Parent.FindForm().BackColor);
  87.         G.FillRectangle(new SolidBrush(Color.FromArgb(96, 110, 121)), new Rectangle(0, 0, ItemSize.Height + 4, Height));
  88.         for (var i = 0; i < TabCount; i++)
  89.         {
  90.             if (i == SelectedIndex)
  91.             {
  92.                 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));
  93.                 ColorBlend myBlend = new ColorBlend();
  94.                 myBlend.Colors = new[] { Color.FromArgb(96, 110, 121), Color.FromArgb(96, 110, 121), Color.FromArgb(96, 110, 121) };
  95.                 myBlend.Positions = new[] { 0.0F, 0.5F, 1.0F };
  96.                 LinearGradientBrush lgBrush = new LinearGradientBrush(x2, Color.Black, Color.Black, 90.0F);
  97.                 lgBrush.InterpolationColors = myBlend;
  98.                 G.FillRectangle(lgBrush, x2);
  99.                 G.DrawRectangle(new Pen(Color.FromArgb(96, 110, 121)), x2);
  100.                 Rectangle tabRect = new Rectangle(GetTabRect(i).Location.X + 4, GetTabRect(i).Location.Y + 2, GetTabRect(i).Size.Width + 10, GetTabRect(i).Size.Height - 11);
  101.                 G.FillPath(new SolidBrush(Color.FromArgb(80, 90, 100)), RoundRect(tabRect, 5));
  102.                 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));
  103.                 G.DrawPath(new Pen(Color.FromArgb(115, 125, 135)), RoundRect(tabRect, 5));
  104.  
  105.                 G.SmoothingMode = SmoothingMode.HighQuality;
  106.  
  107.                 if (_DrawPointer)
  108.                 {
  109.                     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) };
  110.                     G.FillPolygon(Brushes.White, p);
  111.                     Invalidate();
  112.                 }
  113.  
  114.                 if (ImageList != null)
  115.                 {
  116.                     try
  117.                     {
  118.                         if (ImageList.Images[TabPages[i].ImageIndex] != null)
  119.                         {
  120.  
  121.                             G.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(x2.Location.X + 8, x2.Location.Y + 6));
  122.                             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 });
  123.                         }
  124.                         else
  125.                         {
  126.                             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 });
  127.                         }
  128.                     }
  129.                     catch (Exception ex)
  130.                     {
  131.                         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 });
  132.                     }
  133.                 }
  134.                 else
  135.                 {
  136.                     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 });
  137.                 }
  138.  
  139.                 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));
  140.                 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));
  141.             }
  142.             else
  143.             {
  144.                 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));
  145.                 G.FillRectangle(new SolidBrush(Color.FromArgb(96, 110, 121)), x2);
  146.                 G.DrawLine(new Pen(Color.FromArgb(96, 110, 121)), new Point(x2.Right, x2.Top), new Point(x2.Right, x2.Bottom));
  147.                 if (ImageList != null)
  148.                 {
  149.                     try
  150.                     {
  151.                         if (ImageList.Images[TabPages[i].ImageIndex] != null)
  152.                         {
  153.                             G.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(x2.Location.X + 8, x2.Location.Y + 6));
  154.                             G.DrawString("      " + TabPages[i].Text, Font, Brushes.White, x2, new StringFormat { LineAlignment = StringAlignment.Near, Alignment = StringAlignment.Near });
  155.                         }
  156.                         else
  157.                         {
  158.                             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 });
  159.                         }
  160.                     }
  161.                     catch (Exception ex)
  162.                     {
  163.                         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 });
  164.                     }
  165.                 }
  166.                 else
  167.                 {
  168.                     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 });
  169.                 }
  170.             }
  171.             G.FillPath(Brushes.White, RoundRect(new Rectangle(86, 0, Width - 89, Height - 3), 5));
  172.             G.DrawPath(new Pen(Color.FromArgb(65, 75, 85)), RoundRect(new Rectangle(86, 0, Width - 89, Height - 3), 5));
  173.         }
  174.  
  175.         e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  176.         G.Dispose();
  177.         B.Dispose();
  178.     }
  179. }
Add Comment
Please, Sign In to add comment