Advertisement
Temploit

AviraTabControl

May 3rd, 2014
3,456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.89 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2.  
  3. '----------------------------
  4. 'AviraTabControl
  5. 'Creator: Temploit
  6. 'Version: 1.1
  7. 'Created: 3rd of May / ~1.5hr
  8. '----------------------------
  9.  
  10. Public Class AviraTabControl
  11.     Inherits TabControl
  12.  
  13.     Private BC As Color = Color.FromArgb(73, 73, 73) 'Background Color
  14.     Private SLGT As Color = Color.FromArgb(255, 255, 255) 'Selected Tab Gradient Color Top
  15.     Private SLGB As Color = Color.FromArgb(200, 200, 200) 'Selected Tab Gradient Color Bottom
  16.     Private SLLT As Pen = New Pen(Color.FromArgb(165, 165, 165)) 'Selected Tab Line Color Top
  17.     Private SLLB As Pen = New Pen(Color.FromArgb(98, 98, 98)) 'Selected Tab Line Color Bottom
  18.     Private TC As SolidBrush = New SolidBrush(Color.FromArgb(180, 180, 180)) 'Header Text Color
  19.     Private UTC As Brush = Brushes.White 'Unselected Tab Font Color
  20.     Private STC As Brush = Brushes.Black 'Selected Tab Font Color
  21.  
  22.     Private BCB As SolidBrush = New SolidBrush(BC)
  23.     Private BCP As Pen = New Pen(BC)
  24.     Private TR, InTR, InR, LR, ImR As Rectangle
  25.     Private SF As StringFormat = New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Center}
  26.     Private SFHeader As StringFormat = New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Far}
  27.     Private ICounter As Integer = 0
  28.     Private SLGBr As LinearGradientBrush
  29.     Private TSB As SolidBrush
  30.     Private TROffset As Integer = 1
  31.  
  32.     Sub New()
  33.         SetStyle(ControlStyles.UserPaint Or ControlStyles.Opaque Or ControlStyles.ResizeRedraw Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)
  34.         SetStyle(ControlStyles.Selectable, False)
  35.         SizeMode = TabSizeMode.Fixed
  36.         Alignment = TabAlignment.Left
  37.         ItemSize = New Size(21, 180)
  38.         DrawMode = TabDrawMode.OwnerDrawFixed
  39.         Font = New Font("Verdana", 8)
  40.     End Sub
  41.  
  42.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  43.         MyBase.OnPaint(e)
  44.         Dim g As Graphics = e.Graphics
  45.  
  46.         If Not SelectedIndex = Nothing AndAlso Not SelectedIndex = -1 AndAlso Not SelectedIndex > TabPages.Count - 1 AndAlso Not TabPages(SelectedIndex).BackColor = Color.Transparent Then
  47.             g.Clear(TabPages(SelectedIndex).BackColor)
  48.         Else
  49.             g.Clear(Color.White)
  50.         End If
  51.         ICounter = 0
  52.         LR = New Rectangle(0, 0, ItemSize.Height + 3, Height)
  53.         g.FillRectangle(BCB, LR)
  54.         g.DrawRectangle(BCP, LR)
  55.  
  56.         g.SmoothingMode = SmoothingMode.AntiAlias
  57.         For i = 0 To TabCount - 1
  58.             TR = GetTabRect(i)
  59.             TR = New Rectangle(TR.X, TR.Y, TR.Width - 1, TR.Height)
  60.             If TabPages(i).Tag IsNot Nothing AndAlso TabPages(i).Tag IsNot String.Empty Then
  61.                 InR = New Rectangle(TR.X + 10, TR.Y, TR.Width - 10, TR.Height)
  62.                 g.DrawString(TabPages(i).Text.ToUpper, Font, TC, InR, SFHeader)
  63.                 ICounter += 1
  64.             Else
  65.                 If i = SelectedIndex Then
  66.                     SLGBr = New LinearGradientBrush(TR, SLGT, SLGB, 90)
  67.                     InR = New Rectangle(TR.X + 36, TR.Y, TR.Width - 36, TR.Height)
  68.                     InTR = New Rectangle(TR.X, TR.Y + TROffset, TR.Width, TR.Height - (2 * TROffset))
  69.  
  70.                     g.FillRectangle(SLGBr, InTR)
  71.                     g.DrawLine(SLLT, TR.X, TR.Y + TROffset, TR.X + TR.Width - 1, TR.Y + TROffset)
  72.                     g.DrawLine(SLLB, TR.X, TR.Y + TR.Height - TROffset, TR.X + TR.Width - 1, TR.Y + TR.Height - TROffset)
  73.                     g.DrawString(TabPages(i).Text, Font, STC, InR, SF)
  74.  
  75.                     If SelectedImageList IsNot Nothing AndAlso SelectedImageList.Images.Count > i - ICounter AndAlso SelectedImageList.Images(i - ICounter) IsNot Nothing Then
  76.                         ImR = New Rectangle(TR.X + 13, TR.Y + ((TR.Height / 2) - 8), 16, 16)
  77.                         g.DrawImage(SelectedImageList.Images(i - ICounter), ImR)
  78.                     End If
  79.  
  80.                 Else
  81.                     InR = New Rectangle(TR.X + 36, TR.Y, TR.Width - 36, TR.Height)
  82.                     g.DrawString(TabPages(i).Text, Font, UTC, InR, SF)
  83.  
  84.                     If UnselectedImageList IsNot Nothing AndAlso UnselectedImageList.Images.Count > i - ICounter AndAlso UnselectedImageList.Images(i - ICounter) IsNot Nothing Then
  85.                         ImR = New Rectangle(TR.X + 13, TR.Y + ((TR.Height / 2) - 8), 16, 16)
  86.                         g.DrawImage(UnselectedImageList.Images(i - ICounter), ImR)
  87.                     End If
  88.  
  89.                 End If
  90.             End If
  91.         Next
  92.  
  93.  
  94.         g.Dispose()
  95.  
  96.     End Sub
  97.  
  98.     Private UnselectedImageList As ImageList
  99.     Public Property ImageList_Unselected As ImageList
  100.         Get
  101.             Return UnselectedImageList
  102.         End Get
  103.         Set(value As ImageList)
  104.             UnselectedImageList = value
  105.             If UnselectedImageList IsNot Nothing AndAlso Not UnselectedImageList.ImageSize = New Size(16, 16) Then
  106.                 UnselectedImageList.ImageSize = New Size(16, 16)
  107.             End If
  108.             Invalidate()
  109.         End Set
  110.     End Property
  111.  
  112.     Private SelectedImageList As ImageList
  113.     Public Property ImageList_Selected As ImageList
  114.         Get
  115.             Return SelectedImageList
  116.         End Get
  117.         Set(value As ImageList)
  118.             SelectedImageList = value
  119.             If SelectedImageList IsNot Nothing AndAlso Not SelectedImageList.ImageSize = New Size(16, 16) Then
  120.                 SelectedImageList.ImageSize = New Size(16, 16)
  121.             End If
  122.             Invalidate()
  123.         End Set
  124.     End Property
  125.  
  126.     Protected Overrides Sub OnSelecting(e As TabControlCancelEventArgs)
  127.         MyBase.OnSelecting(e)
  128.         If e.TabPage IsNot Nothing AndAlso e.TabPage.Tag IsNot Nothing AndAlso e.TabPage.Tag IsNot String.Empty AndAlso Not DesignMode Then
  129.             e.Cancel = True
  130.         End If
  131.     End Sub
  132.  
  133. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement