Guest User

Custom Tabcontrol

a guest
May 28th, 2016
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.73 KB | None | 0 0
  1. ' Minimal Tabcontrol.
  2. ' Made by Naywyn.
  3.  
  4. Public Class cTabControl
  5.     Inherits TabControl
  6.  
  7.     Private G As Graphics
  8.     Private Rect As Rectangle
  9.  
  10.     Sub New()
  11.         DoubleBuffered = True
  12.         SizeMode = TabSizeMode.Fixed
  13.         ItemSize = New Size(30, 170)
  14.         Alignment = TabAlignment.Left
  15.         SetStyle(ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer, True)
  16.     End Sub
  17.  
  18.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  19.  
  20.         G = e.Graphics
  21.  
  22.         G.Clear(Color.White)
  23.  
  24.         Using Right As New Pen(Color.FromArgb(211, 223, 229))
  25.             G.DrawLine(Right, ItemSize.Height + 3, 4, ItemSize.Height + 3, Height)
  26.         End Using
  27.  
  28.         For T As Integer = 0 To TabPages.Count - 1
  29.  
  30.             Rect = GetTabRect(T)
  31.  
  32.             If SelectedIndex = T Then
  33.  
  34.                 Using TextBrush As New SolidBrush(Color.FromArgb(32, 32, 32)), TextFont As New Font("Verdana", 10)
  35.                     G.DrawString(TabPages(T).Text, TextFont, TextBrush, New Point(Rect.X + 45, Rect.Y + 7))
  36.                 End Using
  37.  
  38.             Else
  39.  
  40.                 Using TextBrush As New SolidBrush(Color.FromArgb(129, 129, 129)), TextFont As New Font("Verdana", 10)
  41.                     G.DrawString(TabPages(T).Text, TextFont, TextBrush, New Point(Rect.X + 45, Rect.Y + 7))
  42.                 End Using
  43.  
  44.             End If
  45.  
  46.             If Not IsNothing(ImageList) Then
  47.                 If Not TabPages(T).ImageIndex < 0 Then
  48.                     G.DrawImage(ImageList.Images(TabPages(T).ImageIndex), New Rectangle(Rect.X + 20, Rect.Y + 7, 16, 16))
  49.                 End If
  50.             End If
  51.  
  52.         Next
  53.  
  54.         MyBase.OnPaint(e)
  55.     End Sub
  56.  
  57. End Class
Advertisement
Add Comment
Please, Sign In to add comment