dafzu

TabControl

Aug 8th, 2014
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2.  
  3. 'Made by Darko155
  4. 'Special thanks to Mavamaarten
  5. 'www.hackforums.net
  6.  
  7. Public Class TabControlClass
  8. Inherits Windows.Forms.TabControl
  9.  
  10. Dim LightColor As Color = Color.FromArgb(95, 105, 127)
  11. Dim DarkColor As Color = Color.FromArgb(71, 80, 100)
  12. Dim LightBrush As New SolidBrush(LightColor)
  13. Dim DarkBrush As New SolidBrush(DarkColor)
  14. Dim NotSelectedColor As New SolidBrush(Color.FromArgb(90, 102, 127))
  15.  
  16.  
  17. Sub New()
  18. SetStyle(ControlStyles.UserPaint Or ControlStyles.Opaque Or ControlStyles.ResizeRedraw Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)
  19. SetStyle(ControlStyles.Selectable, False)
  20. Dock = DockStyle.Fill
  21. SizeMode = TabSizeMode.Fixed
  22. Alignment = TabAlignment.Left
  23. ItemSize = New Size(25, 120)
  24. DrawMode = TabDrawMode.OwnerDrawFixed
  25. Font = New Font("Verdana", 8)
  26. End Sub
  27.  
  28. Protected Overrides Sub CreateHandle()
  29. MyBase.CreateHandle()
  30. Alignment = TabAlignment.Left
  31. End Sub
  32.  
  33. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  34. Dim bm As New Bitmap(Width, Height)
  35. Dim g As Graphics = Graphics.FromImage(bm)
  36. g.Clear(DarkColor)
  37. g.SmoothingMode = SmoothingMode.AntiAlias
  38.  
  39. For i = 0 To TabCount - 1
  40. Dim TabRectangle As Rectangle = GetTabRect(i)
  41. If i = SelectedIndex Then
  42. g.FillRectangle(LightBrush, TabRectangle)
  43. g.FillRectangle(Brushes.DeepSkyBlue, New Rectangle(TabRectangle.Location.X + 2, TabRectangle.Location.Y + 2, 3, TabRectangle.Height - 4))
  44. Else
  45. g.FillRectangle(DarkBrush, TabRectangle)
  46. g.FillRectangle(NotSelectedColor, New Rectangle(TabRectangle.Location.X + 2, TabRectangle.Location.Y + 2, 3, TabRectangle.Height - 4))
  47. End If
  48. g.DrawString(TabPages(i).Text, Font, Brushes.White, TabRectangle, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  49. Next
  50.  
  51. e.Graphics.DrawImage(bm.Clone, 0, 0)
  52. g.Dispose() : bm.Dispose()
  53. MyBase.OnPaint(e)
  54. End Sub
  55.  
  56. End Class
Advertisement
Add Comment
Please, Sign In to add comment