Advertisement
PatPositron

Untitled

Apr 16th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.46 KB | None | 0 0
  1. public class IMTabBarr : TabControl
  2. {
  3.     #region Functions
  4.  
  5.     private Color ChangeLightness(Color color, float coef)
  6.     {
  7.         return Color.FromArgb((int)(color.R * coef), (int)(color.G * coef), (int)(color.B * coef));
  8.     }
  9.    
  10.     #endregion
  11.  
  12.     #region Initialize/Properties
  13.  
  14.     public IMTabBarr()
  15.     {
  16.         SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
  17.         Font = new Font("Verdana", 8F);
  18.         SizeMode = TabSizeMode.Fixed;
  19.         ItemSize = new Size(26, 121);
  20.  
  21.         StringF = new StringFormat { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center };
  22.         //SelectFillBrush = new SolidBrush(Color.FromArgb(30, 30, 30));
  23.         //SelectFillBrush = new LinearGradientBrush(new Point(0, 0), new Point(0, 43), Color.FromArgb(81, 127, 164), Color.FromArgb(48, 96, 136));
  24.         SelectFillBrush = new SolidBrush(Color.FromArgb(48,96,136));
  25.         HoverFillBrush = new SolidBrush(Color.FromArgb(37, 37, 37));
  26.         HighlightColor = Color.FromArgb(81, 126, 210);
  27.     }
  28.  
  29.     public Color Highlight
  30.     {
  31.         get { return HighlightColor; }
  32.         set
  33.         {
  34.             HighlightColor = value;
  35.             Invalidate();
  36.         }
  37.     }
  38.  
  39.     #endregion
  40.  
  41.     #region Overrides
  42.  
  43.     protected override void CreateHandle()
  44.     {
  45.         base.CreateHandle();
  46.         Alignment = TabAlignment.Left;
  47.     }
  48.  
  49.     protected override void OnMouseMove(MouseEventArgs e)
  50.     {
  51.         for (int i = 0; i <= TabCount - 1; i++)
  52.         {
  53.             if (GetTabRect(i).Contains(e.Location))
  54.             {
  55.                 HoverIndex = i;
  56.                 Invalidate();
  57.             }
  58.         }
  59.         base.OnMouseMove(e);
  60.     }
  61.  
  62.     protected override void OnMouseLeave(EventArgs e)
  63.     {
  64.         HoverIndex = -1;
  65.         Invalidate();
  66.         base.OnMouseLeave(e);
  67.     }
  68.  
  69.     protected override void OnPaint(PaintEventArgs e)
  70.     {
  71.         G = e.Graphics;
  72.  
  73.         G.SmoothingMode = SmoothingMode.HighQuality;
  74.  
  75.         G.Clear(DefaultBackColor);
  76.  
  77.         G.FillRectangle(Brushes.White, new Rectangle(0, 0, Width, Height));
  78.         G.FillRectangle(SelectFillBrush, new Rectangle(0, 0, ItemSize.Height + 2, Height));
  79.  
  80.         for (int i = 0; i <= TabCount - 1; i++)
  81.         {
  82.             Rectangle TabRect = GetTabRect(i);
  83.  
  84.             G.DrawLine(new Pen(Color.FromArgb(94, 94, 94)), new Point(TabRect.X, TabRect.Y), new Point(ItemSize.Height + 1, TabRect.Y));
  85.             G.DrawLine(new Pen(SelectFillBrush), new Point(TabRect.X, TabRect.Y - (TabRect.Height - 25)), new Point(ItemSize.Height + 1, TabRect.Y - (TabRect.Height - 25)));
  86.  
  87.             NoSelectFillBrush = new LinearGradientBrush(TabRect, Color.FromArgb(50, 50, 50), Color.FromArgb(41, 41, 41), 90F);
  88.  
  89.             if (i == SelectedIndex)
  90.             {
  91.                 G.FillRectangle(SelectFillBrush, TabRect);
  92.                 G.DrawLine(new Pen(HighlightColor), new Point(TabRect.X + 8, TabRect.Y - (TabRect.Height - 46)), new Point(TabRect.X + (TabRect.Width - 10), TabRect.Y - (TabRect.Height - 46)));
  93.                 G.DrawLine(new Pen(ChangeLightness(HighlightColor, .75F)), new Point(TabRect.X + 8, TabRect.Y - (TabRect.Height - 47)), new Point(TabRect.X + (TabRect.Width - 10), TabRect.Y - (TabRect.Height - 47)));
  94.             }
  95.             else if (i == HoverIndex)
  96.             {
  97.                 G.FillRectangle(HoverFillBrush, TabRect);
  98.             }
  99.             else
  100.             {
  101.                 G.FillRectangle(NoSelectFillBrush, TabRect);
  102.             }
  103.  
  104.             G.DrawString(TabPages[i].Text, Font, Brushes.Black, new Rectangle(TabRect.X + 8, TabRect.Y + 1, TabRect.Width, TabRect.Height), StringF);
  105.             G.DrawString(TabPages[i].Text, Font, Brushes.White, new Rectangle(TabRect.X + 7, TabRect.Y, TabRect.Width, TabRect.Height), StringF);
  106.         }
  107.  
  108.         G.DrawLine(Pens.Black, new Point(ItemSize.Height + 2, 1), new Point(ItemSize.Height + 2, Height));
  109.         //G.DrawLine(new Pen(Color.FromArgb(25, 25, 25)), new Point(2, (TabCount * 26) + 2), new Point(122, (TabCount * 26) + 2));
  110.     }
  111.  
  112.     #endregion
  113.  
  114.     #region Declares
  115.  
  116.     private LinearGradientBrush NoSelectFillBrush;
  117.     private StringFormat StringF;
  118.     private Brush SelectFillBrush, HoverFillBrush;
  119.     private Color HighlightColor;
  120.     private Graphics G;
  121.     private int HoverIndex = -1;
  122.  
  123.     #endregion
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement