Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class IMTabBarr : TabControl
- {
- #region Functions
- private Color ChangeLightness(Color color, float coef)
- {
- return Color.FromArgb((int)(color.R * coef), (int)(color.G * coef), (int)(color.B * coef));
- }
- #endregion
- #region Initialize/Properties
- public IMTabBarr()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
- Font = new Font("Verdana", 8F);
- SizeMode = TabSizeMode.Fixed;
- ItemSize = new Size(26, 121);
- StringF = new StringFormat { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center };
- //SelectFillBrush = new SolidBrush(Color.FromArgb(30, 30, 30));
- //SelectFillBrush = new LinearGradientBrush(new Point(0, 0), new Point(0, 43), Color.FromArgb(81, 127, 164), Color.FromArgb(48, 96, 136));
- SelectFillBrush = new SolidBrush(Color.FromArgb(48,96,136));
- HoverFillBrush = new SolidBrush(Color.FromArgb(37, 37, 37));
- HighlightColor = Color.FromArgb(81, 126, 210);
- }
- public Color Highlight
- {
- get { return HighlightColor; }
- set
- {
- HighlightColor = value;
- Invalidate();
- }
- }
- #endregion
- #region Overrides
- protected override void CreateHandle()
- {
- base.CreateHandle();
- Alignment = TabAlignment.Left;
- }
- protected override void OnMouseMove(MouseEventArgs e)
- {
- for (int i = 0; i <= TabCount - 1; i++)
- {
- if (GetTabRect(i).Contains(e.Location))
- {
- HoverIndex = i;
- Invalidate();
- }
- }
- base.OnMouseMove(e);
- }
- protected override void OnMouseLeave(EventArgs e)
- {
- HoverIndex = -1;
- Invalidate();
- base.OnMouseLeave(e);
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- G = e.Graphics;
- G.SmoothingMode = SmoothingMode.HighQuality;
- G.Clear(DefaultBackColor);
- G.FillRectangle(Brushes.White, new Rectangle(0, 0, Width, Height));
- G.FillRectangle(SelectFillBrush, new Rectangle(0, 0, ItemSize.Height + 2, Height));
- for (int i = 0; i <= TabCount - 1; i++)
- {
- Rectangle TabRect = GetTabRect(i);
- G.DrawLine(new Pen(Color.FromArgb(94, 94, 94)), new Point(TabRect.X, TabRect.Y), new Point(ItemSize.Height + 1, TabRect.Y));
- G.DrawLine(new Pen(SelectFillBrush), new Point(TabRect.X, TabRect.Y - (TabRect.Height - 25)), new Point(ItemSize.Height + 1, TabRect.Y - (TabRect.Height - 25)));
- NoSelectFillBrush = new LinearGradientBrush(TabRect, Color.FromArgb(50, 50, 50), Color.FromArgb(41, 41, 41), 90F);
- if (i == SelectedIndex)
- {
- G.FillRectangle(SelectFillBrush, TabRect);
- 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)));
- 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)));
- }
- else if (i == HoverIndex)
- {
- G.FillRectangle(HoverFillBrush, TabRect);
- }
- else
- {
- G.FillRectangle(NoSelectFillBrush, TabRect);
- }
- G.DrawString(TabPages[i].Text, Font, Brushes.Black, new Rectangle(TabRect.X + 8, TabRect.Y + 1, TabRect.Width, TabRect.Height), StringF);
- G.DrawString(TabPages[i].Text, Font, Brushes.White, new Rectangle(TabRect.X + 7, TabRect.Y, TabRect.Width, TabRect.Height), StringF);
- }
- G.DrawLine(Pens.Black, new Point(ItemSize.Height + 2, 1), new Point(ItemSize.Height + 2, Height));
- //G.DrawLine(new Pen(Color.FromArgb(25, 25, 25)), new Point(2, (TabCount * 26) + 2), new Point(122, (TabCount * 26) + 2));
- }
- #endregion
- #region Declares
- private LinearGradientBrush NoSelectFillBrush;
- private StringFormat StringF;
- private Brush SelectFillBrush, HoverFillBrush;
- private Color HighlightColor;
- private Graphics G;
- private int HoverIndex = -1;
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement