ibennz

Tab

Nov 25th, 2013
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.24 KB | None | 0 0
  1. Class SLCTabControl
  2.     Inherits TabControl
  3.  
  4.     Sub New()
  5.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
  6.         DoubleBuffered = True
  7.         SizeMode = TabSizeMode.Fixed
  8.         ItemSize = New Size(30, 120)
  9.  
  10.     End Sub
  11.  
  12.     Protected Overrides Sub CreateHandle()
  13.         MyBase.CreateHandle()
  14.         Alignment = TabAlignment.Left
  15.     End Sub
  16.  
  17.     Public Function Borderpts() As GraphicsPath
  18.         Dim P As New GraphicsPath()
  19.         Dim PS As New List(Of Point)
  20.  
  21.         PS.Add(New Point(0, 0))
  22.         PS.Add(New Point(Width - 1, 0))
  23.         PS.Add(New Point(Width - 1, Height - 1))
  24.         PS.Add(New Point(0, Height - 1))
  25.  
  26.  
  27.  
  28.         P.AddPolygon(PS.ToArray())
  29.         Return P
  30.     End Function
  31.  
  32.     Public Function BorderptsInside() As GraphicsPath
  33.         Dim P As New GraphicsPath()
  34.         Dim PS As New List(Of Point)
  35.  
  36.         PS.Add(New Point(1, 1))
  37.         PS.Add(New Point(122, 1))
  38.         PS.Add(New Point(122, Height - 2))
  39.         PS.Add(New Point(1, Height - 2))
  40.  
  41.  
  42.  
  43.         P.AddPolygon(PS.ToArray())
  44.         Return P
  45.     End Function
  46.  
  47.     Public Function BigBorder() As GraphicsPath
  48.         Dim P As New GraphicsPath()
  49.         Dim PS As New List(Of Point)
  50.  
  51.         PS.Add(New Point(50, 1))
  52.         PS.Add(New Point(349, 50))
  53.         PS.Add(New Point(349, 50))
  54.         PS.Add(New Point(50, 349))
  55.  
  56.         P.AddPolygon(PS.ToArray())
  57.         Return P
  58.     End Function
  59.  
  60.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  61.  
  62.  
  63.  
  64.         Dim b As New Bitmap(Width, Height)
  65.         Dim g As Graphics = Graphics.FromImage(b)
  66.         g.Clear(Color.FromArgb(40, 40, 40))
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.         Dim GP1 As GraphicsPath = Borderpts()
  75.         g.DrawPath(New Pen(New SolidBrush(Color.FromArgb(20, 20, 20))), GP1)
  76.  
  77.  
  78.         '// small border
  79.         Dim tmp1 As GraphicsPath = BorderptsInside()
  80.  
  81.         Dim PB2 As PathGradientBrush
  82.         PB2 = New PathGradientBrush(tmp1)
  83.         PB2.CenterColor = Color.FromArgb(40, 40, 40)
  84.         PB2.SurroundColors = {Color.FromArgb(50, 50, 50)}
  85.         PB2.FocusScales = New PointF(0.9F, 0.9F)
  86.  
  87.         g.FillPath(PB2, tmp1)
  88.         'g.DrawPath(New Pen(New SolidBrush(Color.FromArgb(20, 20, 20))), tmp1)
  89.  
  90.  
  91.  
  92.  
  93.         '// items
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.         For i = 0 To TabCount - 1
  101.  
  102.             Dim rec As Rectangle = GetTabRect(i)
  103.             Dim rec2 As Rectangle = rec
  104.  
  105.  
  106.             '//inside small
  107.             rec2.Width -= 3
  108.             rec2.Height -= 3
  109.             rec2.Y += 1
  110.             rec2.X += 1
  111.  
  112.  
  113.  
  114.  
  115.             If i = SelectedIndex Then
  116.  
  117.  
  118.  
  119.                 Dim linear As New LinearGradientBrush(New Rectangle(rec2.X + 108, rec2.Y + 1, 10, rec2.Height - 1), Color.FromArgb(60, 60, 60), Color.Transparent, 200.0F)
  120.                 Dim linear3 As New LinearGradientBrush(New Rectangle(rec2.X, rec2.Y + 1, 10, rec2.Height - 1), Color.FromArgb(60, 60, 60), Color.Transparent, 200.0F)
  121.  
  122.  
  123.                 g.FillRectangle(New SolidBrush(Color.FromArgb(40, 40, 40)), rec2)
  124.                 g.DrawRectangle(New Pen(New SolidBrush(Color.FromArgb(60, 60, 60))), rec2)
  125.                 g.DrawRectangle(New Pen(Color.FromArgb(70, Color.FromArgb(60, 60, 60)), 2), rec)
  126.                 g.FillRectangle(linear, New Rectangle(rec2.X + 113, rec2.Y + 1, 6, rec2.Height - 1))
  127.                 g.FillRectangle(linear3, New Rectangle(rec2.X, rec2.Y + 1, 6, rec2.Height - 1))
  128.  
  129.  
  130.                 g.SmoothingMode = SmoothingMode.AntiAlias
  131.  
  132.                 Dim GP2 As New GraphicsPath
  133.                 GP2.AddPolygon(New Point() {New Point(rec2.X - 4, rec2.Y + 23), New Point(rec2.X - 4, rec2.Y + 5), New Point(rec.X + 12, rec.Y + 15)})
  134.                 g.DrawPath(New Pen(New SolidBrush(Color.Black), 1), GP2)
  135.  
  136.                 Dim GP3 As New GraphicsPath
  137.                 GP3.AddPolygon(New Point() {New Point(rec2.X - 3, rec2.Y + 21), New Point(rec2.X - 3, rec2.Y + 7), New Point(rec.X + 11, rec.Y + 15)})
  138.                 g.DrawPath(New Pen(New SolidBrush(Color.FromArgb(90, 90, 90)), 1), GP3)
  139.  
  140.  
  141.                 Dim GP4 As New GraphicsPath
  142.                 GP4.AddPolygon(New Point() {New Point(rec2.X + 119, rec2.Y + 22), New Point(rec2.X + 119, rec2.Y + 6), New Point(rec2.X + 105, rec2.Y + 15)})
  143.                 g.DrawPath(New Pen(New SolidBrush(Color.Black), 1), GP4)
  144.  
  145.                 Dim GP5 As New GraphicsPath
  146.                 GP5.AddPolygon(New Point() {New Point(rec2.X + 119, rec2.Y + 21), New Point(rec2.X + 119, rec2.Y + 7), New Point(rec2.X + 106, rec2.Y + 15)})
  147.                 g.DrawPath(New Pen(New SolidBrush(Color.FromArgb(90, 90, 90)), 1), GP5)
  148.  
  149.                 g.SmoothingMode = SmoothingMode.None
  150.  
  151.             Else
  152.  
  153.                 g.SmoothingMode = SmoothingMode.HighQuality
  154.                 Dim linear As New LinearGradientBrush(New Rectangle(rec2.X + 108, rec2.Y + 1, 10, rec2.Height - 1), Color.FromArgb(60, 60, 60), Color.Transparent, 200.0F)
  155.                 Dim linear3 As New LinearGradientBrush(New Rectangle(rec2.X, rec2.Y + 1, 10, rec2.Height - 1), Color.FromArgb(60, 60, 60), Color.Transparent, 200.0F)
  156.  
  157.  
  158.                 g.FillRectangle(New SolidBrush(Color.FromArgb(40, 40, 40)), rec2)
  159.                 g.DrawRectangle(New Pen(New SolidBrush(Color.FromArgb(60, 60, 60))), rec2)
  160.                 g.DrawRectangle(New Pen(Color.FromArgb(70, Color.FromArgb(60, 60, 60)), 2), rec)
  161.                 'g.FillRectangle(linear, New Rectangle(rec2.X + 112, rec2.Y + 1, 6, rec2.Height - 1))
  162.                 'g.FillRectangle(linear3, New Rectangle(rec2.X, rec2.Y + 1, 6, rec2.Height - 1))
  163.  
  164.  
  165.                 g.SmoothingMode = SmoothingMode.None
  166.  
  167.             End If
  168.  
  169.             g.DrawString(TabPages(i).Text, Font, New SolidBrush(Color.FromArgb(69, 202, 83)), rec, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  170.         Next
  171.  
  172.  
  173.  
  174.  
  175.         e.Graphics.DrawImage(b.Clone, 0, 0)
  176.         g.Dispose()
  177.         b.Dispose()
  178.         MyBase.OnPaint(e)
  179.     End Sub
  180.  
  181.     Protected Overrides Sub OnControlAdded(ByVal e As ControlEventArgs)
  182.         If TypeOf e.Control Is TabPage Then
  183.             e.Control.BackColor = Color.FromArgb(40, 40, 40)
  184.         End If
  185.  
  186.         MyBase.OnControlAdded(e)
  187.     End Sub
  188. End Class
Advertisement
Add Comment
Please, Sign In to add comment