Advertisement
deSantoz

CustomTabControl

Sep 10th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 57.66 KB | None | 0 0
  1. Imports System.ComponentModel
  2. Imports System.Drawing.Drawing2D
  3. Imports System.Drawing
  4.  
  5. Public Class MyCustomTab
  6.     Inherits TabControl
  7. #Region "Enumeration"
  8.     Enum LinePosition
  9.         Top
  10.         Right
  11.         Left
  12.         Bottom
  13.     End Enum
  14.  
  15.     Enum ImageTextPosition
  16.         ImageBeforeText
  17.         ImageAfterText
  18.         ImageBelowText
  19.         ImageAboveText
  20.     End Enum
  21.  
  22.     Enum CloseButtonImage
  23.         Light
  24.         Dark
  25.     End Enum
  26. #End Region
  27.  
  28. #Region "Declaration"
  29.     Private selectedcolor As Color
  30.     Private unselectedcolor As Color
  31.     Private horizontalheaderalignment As StringAlignment
  32.     Private verticalheaderalignment As StringAlignment
  33.     Private headertextorientation As StringFormatFlags
  34.     Private tabheaderfontcolor As Color
  35.     Private _isMouseHover As Boolean = False
  36.     Private hotcolor As Color
  37.     Private selectedFC As Color
  38.     Private ToogleText As Boolean = True
  39.     Private isShowTriangle As Boolean = False
  40.     Private _TriangleColor As Color
  41.     Private isShowUnderline As Boolean = False
  42.     Private _UnderlineColor As Color
  43.     Private _UnderlineWidth As Single
  44.     Private _ImageList2 As ImageList
  45.     Private _SelectedFontStyle As FontStyle
  46.     Private _LinePosition As LinePosition
  47.     Private _ShowBaseLine As Boolean = False
  48.     Private _BaseLineColor As Color
  49.     Private _ImageTextPosition As ImageTextPosition
  50.     Private _ShowCloseButton As Boolean
  51.     Private _ImageForCloseButton As CloseButtonImage
  52.     Private _ImageForSelectedCloseButton As CloseButtonImage
  53.     Private X3 As Rectangle
  54. #End Region
  55.  
  56. #Region " Properties "
  57.     Dim p As PointF()
  58.     Public Property ImageForSelectedCloseButton As CloseButtonImage
  59.         Get
  60.             Return _ImageForSelectedCloseButton
  61.         End Get
  62.         Set(value As CloseButtonImage)
  63.  
  64.         End Set
  65.     End Property
  66.     Public Property ImageForCloseButton As CloseButtonImage
  67.         Get
  68.             Return _ImageForCloseButton
  69.         End Get
  70.         Set(value As CloseButtonImage)
  71.             _ImageForCloseButton = value
  72.             Invalidate()
  73.         End Set
  74.     End Property
  75.  
  76.  
  77.     Public Property ShowCloseButton As Boolean
  78.         Get
  79.             Return _ShowCloseButton
  80.         End Get
  81.         Set(value As Boolean)
  82.             _ShowCloseButton = value
  83.             Invalidate()
  84.         End Set
  85.     End Property
  86.     Public Property ImageAndTextPosition As ImageTextPosition
  87.         Get
  88.             Return _ImageTextPosition
  89.         End Get
  90.         Set(value As ImageTextPosition)
  91.             _ImageTextPosition = value
  92.             Invalidate()
  93.         End Set
  94.     End Property
  95.     Public Property ShowBaseLine As Boolean
  96.         Get
  97.             Return _ShowBaseLine
  98.         End Get
  99.         Set(value As Boolean)
  100.             _ShowBaseLine = value
  101.             Invalidate()
  102.         End Set
  103.     End Property
  104.  
  105.     Public Property BaseLineColor As Color
  106.         Get
  107.             Return _BaseLineColor
  108.         End Get
  109.         Set(value As Color)
  110.             _BaseLineColor = value
  111.             Invalidate()
  112.         End Set
  113.     End Property
  114.     Public Property UnderlinePosition As LinePosition
  115.         Get
  116.             Return _LinePosition
  117.         End Get
  118.         Set(value As LinePosition)
  119.             _LinePosition = value
  120.             Invalidate()
  121.         End Set
  122.     End Property
  123.  
  124.  
  125.     Public Property SelectedFontStyle As FontStyle
  126.         Get
  127.             Return _SelectedFontStyle
  128.         End Get
  129.         Set(value As FontStyle)
  130.             _SelectedFontStyle = value
  131.             Invalidate()
  132.         End Set
  133.     End Property
  134.     Public Property SelectedImageList As ImageList
  135.         Get
  136.             Return _ImageList2
  137.         End Get
  138.         Set(value As ImageList)
  139.             _ImageList2 = value
  140.             Invalidate()
  141.         End Set
  142.     End Property
  143.  
  144.     Public Property UnderlineWidth As Single
  145.         <DefaultValue(3)>
  146.         Get
  147.             Return _UnderlineWidth
  148.         End Get
  149.         Set(value As Single)
  150.             _UnderlineWidth = value
  151.             Invalidate()
  152.         End Set
  153.     End Property
  154.     Public Property ShowUnderline As Boolean
  155.         Get
  156.             Return isShowUnderline
  157.         End Get
  158.         Set(value As Boolean)
  159.             isShowUnderline = value
  160.             Invalidate()
  161.         End Set
  162.     End Property
  163.     Public Property UnderlineColor As Color
  164.         Get
  165.             Return _UnderlineColor
  166.         End Get
  167.         Set(value As Color)
  168.             _UnderlineColor = value
  169.             Invalidate()
  170.         End Set
  171.     End Property
  172.     Public Property TriangleColor As Color
  173.         Get
  174.             Return _TriangleColor
  175.         End Get
  176.         Set(value As Color)
  177.             _TriangleColor = value
  178.             Invalidate()
  179.         End Set
  180.     End Property
  181.     Public Property ToogleHeaderText As Boolean
  182.         Get
  183.             Return ToogleText
  184.         End Get
  185.         Set(value As Boolean)
  186.             ToogleText = value
  187.             Invalidate()
  188.         End Set
  189.     End Property
  190.     Public Property ShowTriangle As Boolean
  191.         Get
  192.             Return isShowTriangle
  193.         End Get
  194.         Set(value As Boolean)
  195.             isShowTriangle = value
  196.             Invalidate()
  197.         End Set
  198.     End Property
  199.     Public Property HotTrackColor As Color
  200.         <DefaultValue(GetType(Color), "Black")>
  201.         Get
  202.             Return hotcolor
  203.         End Get
  204.         Set(value As Color)
  205.             hotcolor = value
  206.             Invalidate()
  207.         End Set
  208.     End Property
  209.     Public Property SelectedFontColor As Color
  210.         <DefaultValue(GetType(Color), "Black")>
  211.         Get
  212.             Return selectedFC
  213.         End Get
  214.         Set(value As Color)
  215.             selectedFC = value
  216.             Invalidate()
  217.         End Set
  218.     End Property
  219.     Public Property HeaderSelectedColor As Color
  220.         <DefaultValue(GetType(Color), "Blue")>
  221.         Get
  222.             Return selectedcolor
  223.         End Get
  224.         Set(ByVal value As Color)
  225.             selectedcolor = value
  226.             Invalidate()
  227.         End Set
  228.     End Property
  229.     Public Property HeaderUnselectedColor As Color
  230.         <DefaultValue(GetType(Color), "DarkBlue")>
  231.         Get
  232.             Return unselectedcolor
  233.         End Get
  234.         Set(ByVal value As Color)
  235.             unselectedcolor = value
  236.             Invalidate()
  237.         End Set
  238.     End Property
  239.     Public Property HorizontalHeader As System.Drawing.StringAlignment
  240.         Get
  241.             Return horizontalheaderalignment
  242.         End Get
  243.         Set(ByVal value As System.Drawing.StringAlignment)
  244.             horizontalheaderalignment = value
  245.             Invalidate()
  246.         End Set
  247.     End Property
  248.     Public Property VerticalHeader As System.Drawing.StringAlignment
  249.         Get
  250.             Return verticalheaderalignment
  251.         End Get
  252.         Set(ByVal value As System.Drawing.StringAlignment)
  253.             verticalheaderalignment = value
  254.             Invalidate()
  255.         End Set
  256.     End Property
  257.     Public Property HeaderLayout As System.Drawing.StringFormatFlags
  258.         Get
  259.             Return headertextorientation
  260.         End Get
  261.         Set(ByVal value As System.Drawing.StringFormatFlags)
  262.             headertextorientation = value
  263.             Invalidate()
  264.         End Set
  265.     End Property
  266.     Public Property HeaderFontColor As Color
  267.         <DefaultValue(GetType(Color), "Black")>
  268.         Get
  269.             Return tabheaderfontcolor
  270.         End Get
  271.         Set(ByVal value As Color)
  272.             tabheaderfontcolor = value
  273.             Invalidate()
  274.         End Set
  275.     End Property
  276.     Public Overrides ReadOnly Property DisplayRectangle As System.Drawing.Rectangle
  277.         Get
  278.             Dim rc As Rectangle = MyBase.DisplayRectangle
  279.             rc.Offset(0, 0)
  280.             rc.Width += 1
  281.             rc.Inflate(4, 4)
  282.             Return rc
  283.         End Get
  284.     End Property
  285. #End Region
  286.  
  287.     Sub New()
  288.         InitializeComponent()
  289.         SetStyle(ControlStyles.AllPaintingInWmPaint _
  290.                  Or ControlStyles.OptimizedDoubleBuffer _
  291.                  Or ControlStyles.ResizeRedraw _
  292.                  Or ControlStyles.UserPaint _
  293.                  Or ControlStyles.SupportsTransparentBackColor, True)
  294.         DoubleBuffered = True
  295.         HeaderFontColor = Color.Black
  296.         SelectedFontColor = Color.Black
  297.         HeaderSelectedColor = Color.White
  298.         HeaderUnselectedColor = Color.AliceBlue
  299.         HotTrackColor = Color.FromArgb(40, 0, 0, 0)
  300.         UnderlineWidth = 3
  301.         SelectedFontStyle = FontStyle.Bold
  302.         _ImageTextPosition = ImageTextPosition.ImageBeforeText
  303.         ImageForCloseButton = CloseButtonImage.Dark
  304.         ImageForSelectedCloseButton = CloseButtonImage.Dark
  305.         ShowCloseButton = False
  306.     End Sub
  307.  
  308.     Private _mouseRect As Rectangle
  309.     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  310.         MyBase.OnMouseMove(e)
  311.         _isMouseHover = True
  312.         _mouseRect = New Rectangle(e.X, e.Y, 1, 1)
  313.         Invalidate()
  314.     End Sub
  315.  
  316.     Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  317.         MyBase.OnMouseLeave(e)
  318.         _isMouseHover = False
  319.         Invalidate()
  320.     End Sub
  321.  
  322.     Protected Overrides Sub OnClick(e As EventArgs)
  323.         MyBase.OnClick(e)
  324.         For i = 0 To TabCount - 1
  325.             MsgBox(GetTabRect(i).ToString & " " & X3.ToString)
  326.             If GetTabRect(i).Contains(X3) = True Then
  327.                 If _mouseRect.IntersectsWith(X3) = True Then
  328.                     TabPages.RemoveAt(i)
  329.                 End If
  330.             End If
  331.         Next
  332.  
  333.     End Sub
  334.  
  335.     Protected Overrides Sub CreateHandle()
  336.         MyBase.CreateHandle()
  337.     End Sub
  338.  
  339.     Protected Overrides Sub OnPaintBackground(ByVal pevent As PaintEventArgs)
  340.         MyBase.OnPaintBackground(pevent)
  341.         Me.InvokePaintBackground(Me.Parent, pevent)
  342.         Me.InvokePaint(Me.Parent, pevent)
  343.     End Sub
  344.  
  345.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  346.  
  347.         Dim UC As New SolidBrush(unselectedcolor)
  348.         Dim white As New SolidBrush(selectedcolor)
  349.         Dim FC As New SolidBrush(HeaderFontColor)
  350.         Dim HC As New SolidBrush(hotcolor)
  351.         Dim SFC As New SolidBrush(SelectedFontColor)
  352.         Dim TC As New SolidBrush(TriangleColor)
  353.         Dim ULC As New SolidBrush(UnderlineColor)
  354.         Dim B As New Bitmap(Width, Height)
  355.         Dim G As Graphics = Graphics.FromImage(B)
  356.         G.Clear(Color.Transparent)
  357.  
  358.  
  359.  
  360.         For i = 0 To TabCount - 1
  361.             Dim tabrectangel As Rectangle = GetTabRect(i)
  362.  
  363.             tabrectangel.Inflate(1, 1)
  364.  
  365.             If SelectedIndex = i Then
  366.                 '//jika tab dipilih
  367.                 G.FillRectangle(white, tabrectangel)
  368.                 G.SmoothingMode = SmoothingMode.HighQuality
  369.  
  370.                 If _isMouseHover Then
  371.                     If tabrectangel.IntersectsWith(_mouseRect) Then
  372.                         G.FillRectangle(HC, tabrectangel)
  373.                     End If
  374.                 End If
  375.             Else
  376.                 '//jika tab tidak dipilih
  377.                 G.FillRectangle(UC, tabrectangel)
  378.                 G.SmoothingMode = SmoothingMode.HighQuality
  379.  
  380.                 If _isMouseHover Then
  381.                     If tabrectangel.IntersectsWith(_mouseRect) Then
  382.                         G.FillRectangle(HC, tabrectangel)
  383.                     End If
  384.                 End If
  385.             End If
  386.  
  387.  
  388.             If SelectedIndex = i Then
  389.                 'draw line in each tab
  390.                 If isShowUnderline = True And _UnderlineWidth > 0 Then
  391.                     Select Case Alignment
  392.                         Case TabAlignment.Left
  393.                             Select Case UnderlinePosition
  394.                                 Case LinePosition.Top
  395.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  396.                                     New Point(GetTabRect(i).Location.X - 1, GetTabRect(i).Location.Y),
  397.                                     New Point(GetTabRect(i).Location.X + GetTabRect(i).Height, GetTabRect(i).Location.Y))
  398.                                 Case LinePosition.Bottom
  399.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  400.                                     New Point(GetTabRect(i).Location.X - 1, GetTabRect(i).Location.Y + GetTabRect(i).Width - 2),
  401.                                     New Point(GetTabRect(i).Location.X + GetTabRect(i).Height, GetTabRect(i).Location.Y + GetTabRect(i).Width - 2))
  402.                                 Case LinePosition.Right
  403.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  404.                                     New Point(GetTabRect(i).Location.X + GetTabRect(i).Height - 2, GetTabRect(i).Location.Y),
  405.                                     New Point(GetTabRect(i).Location.X + GetTabRect(i).Height - 2, GetTabRect(i).Location.Y + GetTabRect(i).Width))
  406.                                 Case LinePosition.Left
  407.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  408.                                     New Point(GetTabRect(i).Location.X - 1, GetTabRect(i).Location.Y),
  409.                                     New Point(GetTabRect(i).Location.X - 1, GetTabRect(i).Location.Y + GetTabRect(i).Width))
  410.                             End Select
  411.                         Case TabAlignment.Right
  412.                             Select Case UnderlinePosition
  413.                                 Case LinePosition.Top
  414.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  415.                                     New Point(Me.Width - GetTabRect(i).Height, GetTabRect(i).Location.Y),
  416.                                     New Point(Me.Width, GetTabRect(i).Location.Y))
  417.                                 Case LinePosition.Bottom
  418.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  419.                                     New Point(Me.Width - GetTabRect(i).Height, GetTabRect(i).Location.Y + GetTabRect(i).Width - 2),
  420.                                     New Point(Me.Width, GetTabRect(i).Location.Y + GetTabRect(i).Width - 2))
  421.                                 Case LinePosition.Right
  422.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  423.                                     New Point(Me.Width - 2, GetTabRect(i).Location.Y),
  424.                                     New Point(Me.Width - 2, GetTabRect(i).Location.Y + GetTabRect(i).Width))
  425.                                 Case LinePosition.Left
  426.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  427.                                     New Point(Me.Width - GetTabRect(i).Height, GetTabRect(i).Location.Y),
  428.                                     New Point(Me.Width - GetTabRect(i).Height, GetTabRect(i).Location.Y + GetTabRect(i).Width))
  429.                             End Select
  430.                         Case TabAlignment.Top
  431.                             Select Case UnderlinePosition
  432.                                 Case LinePosition.Top
  433.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  434.                                     New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y),
  435.                                     New Point(GetTabRect(i).Location.X + GetTabRect(i).Width, GetTabRect(i).Location.Y))
  436.                                 Case LinePosition.Bottom
  437.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  438.                                     New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y + GetTabRect(i).Height - 2),
  439.                                     New Point(GetTabRect(i).Location.X + GetTabRect(i).Width, GetTabRect(i).Location.Y + GetTabRect(i).Height - 2))
  440.                                 Case LinePosition.Right
  441.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  442.                                     New Point(GetTabRect(i).Location.X + GetTabRect(i).Width - 2, GetTabRect(i).Location.Y),
  443.                                     New Point(GetTabRect(i).Location.X + GetTabRect(i).Width - 2, GetTabRect(i).Location.Y + GetTabRect(i).Height - 2))
  444.                                 Case LinePosition.Left
  445.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  446.                                     New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y),
  447.                                     New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y + GetTabRect(i).Height - 2))
  448.                             End Select
  449.                         Case TabAlignment.Bottom
  450.                             Select Case UnderlinePosition
  451.                                 Case LinePosition.Top
  452.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  453.                                     New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y + 2),
  454.                                     New Point(GetTabRect(i).Location.X + GetTabRect(i).Width, GetTabRect(i).Location.Y + 2))
  455.                                 Case LinePosition.Bottom
  456.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  457.                                     New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y + GetTabRect(i).Height - 2),
  458.                                     New Point(GetTabRect(i).Location.X + GetTabRect(i).Width, GetTabRect(i).Location.Y + GetTabRect(i).Height - 2))
  459.                                 Case LinePosition.Right
  460.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  461.                                     New Point(GetTabRect(i).Location.X + GetTabRect(i).Width - 2, GetTabRect(i).Location.Y),
  462.                                     New Point(GetTabRect(i).Location.X + GetTabRect(i).Width - 2, GetTabRect(i).Location.Y + GetTabRect(i).Width - 2))
  463.                                 Case LinePosition.Left
  464.                                     G.DrawLine(New Pen(ULC, _UnderlineWidth),
  465.                                     New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y),
  466.                                     New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y + GetTabRect(i).Width - 2))
  467.                             End Select
  468.  
  469.                     End Select
  470.                 ElseIf isShowUnderline = True And _UnderlineWidth <= 0 Then
  471.                     If Me.DesignMode = True Then
  472.                         MsgBox("Value must be higher than 0", MsgBoxStyle.Exclamation)
  473.                         isShowUnderline = False
  474.                         _UnderlineWidth = 3
  475.                     End If
  476.                 End If
  477.                 'draw pointed triangle
  478.                 If isShowTriangle = True Then
  479.                     Select Case Me.Alignment
  480.                         Case TabAlignment.Left
  481.                             G.SmoothingMode = SmoothingMode.AntiAlias
  482.                             Dim p() As Point = {New Point(GetTabRect(i).Height - 7, GetTabRect(i).Location.Y + (GetTabRect(i).Width / 2)),
  483.                                 New Point(GetTabRect(i).Height + 5, GetTabRect(i).Location.Y + (GetTabRect(i).Width / 2) - 10),
  484.                                 New Point(GetTabRect(i).Height + 5, GetTabRect(i).Location.Y + (GetTabRect(i).Width / 2) + 10)}
  485.                             G.FillPolygon(TC, p)
  486.                             G.DrawPolygon(New Pen(TC), p)
  487.                         Case TabAlignment.Right
  488.                             G.SmoothingMode = SmoothingMode.AntiAlias
  489.                             Dim p() As Point = {New Point(Me.Width - GetTabRect(i).Height + 7, GetTabRect(i).Location.Y + (GetTabRect(i).Width / 2)),
  490.                                 New Point(Me.Width - GetTabRect(i).Height - 3, GetTabRect(i).Location.Y + (GetTabRect(i).Width / 2) - 10),
  491.                                 New Point(Me.Width - GetTabRect(i).Height - 3, GetTabRect(i).Location.Y + (GetTabRect(i).Width / 2) + 10)}
  492.                             G.FillPolygon(TC, p)
  493.                             G.DrawPolygon(New Pen(TC), p)
  494.                         Case TabAlignment.Top
  495.                             G.SmoothingMode = SmoothingMode.AntiAlias
  496.                             Dim p() As Point = {New Point(GetTabRect(i).Location.X + (GetTabRect(i).Width / 2), GetTabRect(i).Height - 7),
  497.                                 New Point(GetTabRect(i).Location.X + (GetTabRect(i).Width / 2) - 10, GetTabRect(i).Location.Y + GetTabRect(i).Height),
  498.                                 New Point(GetTabRect(i).Location.X + (GetTabRect(i).Width / 2) + 10, GetTabRect(i).Location.Y + GetTabRect(i).Height)}
  499.                             G.FillPolygon(TC, p)
  500.                             G.DrawPolygon(New Pen(TC), p)
  501.                         Case TabAlignment.Bottom
  502.                             G.SmoothingMode = SmoothingMode.AntiAlias
  503.                             Dim p() As Point = {New Point(GetTabRect(i).Location.X + (GetTabRect(i).Width / 2), Me.Height - GetTabRect(i).Height + 7),
  504.                                 New Point(GetTabRect(i).Location.X + (GetTabRect(i).Width / 2) - 10, GetTabRect(i).Location.Y - 2),
  505.                                 New Point(GetTabRect(i).Location.X + (GetTabRect(i).Width / 2) + 10, GetTabRect(i).Location.Y - 2)}
  506.                             G.FillPolygon(TC, p)
  507.                             G.DrawPolygon(New Pen(TC), p)
  508.                     End Select
  509.                 End If
  510.  
  511.                 'Draw image
  512.                 Dim x2 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y), New Size(GetTabRect(i).Width, GetTabRect(i).Height))
  513.                 Dim textsize As SizeF = G.MeasureString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle))
  514.                 If SelectedImageList IsNot Nothing Then
  515.                     Try
  516.                         If SelectedImageList.Images(TabPages(i).ImageIndex) IsNot Nothing Then
  517.                             If ToogleHeaderText = True Then
  518.                                 Select Case Alignment
  519.                                     Case TabAlignment.Top
  520.                                         Select Case ImageAndTextPosition
  521.                                             Case ImageTextPosition.ImageBeforeText
  522.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  523.                                                 G.DrawString("      " & TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  524.                                             Case ImageTextPosition.ImageAfterText
  525.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + x2.Width - SelectedImageList.ImageSize.Width - 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  526.                                                 G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  527.                                             Case ImageTextPosition.ImageAboveText
  528.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + (x2.Width - SelectedImageList.ImageSize.Width) / 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 5))
  529.                                                 G.DrawString(TabPages(i).Text,
  530.                                                              New Font(MyBase.Font, SelectedFontStyle),
  531.                                                              SFC,
  532.                                                              (x2.Location.X + (x2.Width - textsize.Width) / 2) - 2,
  533.                                                              (x2.Location.Y + x2.Height - SelectedImageList.ImageSize.Height - 2))
  534.  
  535.                                             Case ImageTextPosition.ImageBelowText
  536.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex),
  537.                                                             New Point((x2.Location.X + (x2.Width - SelectedImageList.ImageSize.Width) / 2),
  538.                                                                     (x2.Location.Y + (x2.Height - (textsize.Height + 4 + SelectedImageList.ImageSize.Height)) / 2) + textsize.Height + 5))
  539.                                                 G.DrawString(TabPages(i).Text,
  540.                                                              New Font(MyBase.Font, SelectedFontStyle),
  541.                                                              SFC,
  542.                                                              (x2.Location.X + (x2.Width - textsize.Width) / 2) - 2,
  543.                                                              (x2.Location.Y + (x2.Height - (textsize.Height + 4 + SelectedImageList.ImageSize.Height)) / 2))
  544.                                         End Select
  545.  
  546.  
  547.                                     Case TabAlignment.Bottom
  548.                                         Select Case ImageAndTextPosition
  549.                                             Case ImageTextPosition.ImageBeforeText
  550.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 4, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) + 2))
  551.                                                 G.DrawString("      " & TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  552.                                             Case ImageTextPosition.ImageAfterText
  553.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + x2.Width - ImageList.ImageSize.Width - 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  554.                                                 G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  555.                                             Case ImageTextPosition.ImageAboveText
  556.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 5))
  557.                                                 G.DrawString(TabPages(i).Text,
  558.                                                              New Font(MyBase.Font, SelectedFontStyle),
  559.                                                              SFC,
  560.                                                              (x2.Location.X + (x2.Width - textsize.Width) / 2) - 2,
  561.                                                              (x2.Location.Y + x2.Height - ImageList.ImageSize.Height - 2))
  562.                                             Case ImageTextPosition.ImageBelowText
  563.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex),
  564.                                                           New Point((x2.Location.X + (x2.Width - SelectedImageList.ImageSize.Width) / 2),
  565.                                                                     (x2.Location.Y + (x2.Height - (textsize.Height + 4 + SelectedImageList.ImageSize.Height)) / 2) + textsize.Height))
  566.                                                 G.DrawString(TabPages(i).Text,
  567.                                                              New Font(MyBase.Font, SelectedFontStyle),
  568.                                                              SFC,
  569.                                                              (x2.Location.X + (x2.Width - textsize.Width) / 2) - 2,
  570.                                                              (x2.Location.Y + (x2.Height - (textsize.Height + 4 + SelectedImageList.ImageSize.Height)) / 2))
  571.                                         End Select
  572.  
  573.                                     Case TabAlignment.Right
  574.                                         Select Case ImageAndTextPosition
  575.                                             Case ImageTextPosition.ImageBeforeText
  576.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 10, x2.Location.Y + ((x2.Height - SelectedImageList.ImageSize.Height) / 2)))
  577.                                                 G.DrawString("       " & TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  578.                                             Case ImageTextPosition.ImageAfterText
  579.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + x2.Width - SelectedImageList.ImageSize.Width, x2.Location.Y + ((x2.Height - SelectedImageList.ImageSize.Height) / 2)))
  580.                                                 G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  581.                                             Case ImageTextPosition.ImageAboveText
  582.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 3))
  583.                                                 G.DrawString(TabPages(i).Text,
  584.                                                              New Font(MyBase.Font, SelectedFontStyle),
  585.                                                              SFC,
  586.                                                              (x2.Location.X + (x2.Width - textsize.Width) / 2),
  587.                                                              (x2.Location.Y + x2.Height - SelectedImageList.ImageSize.Height - 2))
  588.                                             Case ImageTextPosition.ImageBelowText
  589.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex),
  590.                                                        New Point((x2.Location.X + (x2.Width - SelectedImageList.ImageSize.Width) / 2),
  591.                                                                  (x2.Location.Y + (x2.Height - (textsize.Height + 2 + SelectedImageList.ImageSize.Height)) / 2) + textsize.Height))
  592.                                                 G.DrawString(TabPages(i).Text,
  593.                                                              New Font(MyBase.Font, SelectedFontStyle),
  594.                                                              SFC,
  595.                                                              (x2.Location.X + (x2.Width - textsize.Width) / 2) - 2,
  596.                                                              (x2.Location.Y + (x2.Height - (textsize.Height + SelectedImageList.ImageSize.Height)) / 2) - 2)
  597.                                         End Select
  598.  
  599.                                     Case TabAlignment.Left
  600.                                         Select Case ImageAndTextPosition
  601.                                             Case ImageTextPosition.ImageBeforeText
  602.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  603.                                                 G.DrawString("       " & TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  604.                                             Case ImageTextPosition.ImageAfterText
  605.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + x2.Height - ImageList.ImageSize.Width - 2), x2.Location.Y + ((x2.Width - ImageList.ImageSize.Height) / 2) - 2))
  606.                                                 G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  607.                                             Case ImageTextPosition.ImageAboveText
  608.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex),
  609.                                                             New Point((x2.Location.X + ((x2.Width - SelectedImageList.ImageSize.Height) / 2)),
  610.                                                                       (x2.Location.Y + (x2.Width - SelectedImageList.ImageSize.Width) / 2) - (textsize.Height / 2)))
  611.                                                 G.DrawString(TabPages(i).Text,
  612.                                                              New Font(MyBase.Font, SelectedFontStyle),
  613.                                                              SFC,
  614.                                                              x2.Location.X + (x2.Height - textsize.Width) / 2,
  615.                                                              x2.Location.Y + ((x2.Width - (SelectedImageList.ImageSize.Height + textsize.Height)) / 2) + SelectedImageList.ImageSize.Height
  616.                                                              )
  617.                                             Case ImageTextPosition.ImageBelowText
  618.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex),
  619.                                                        New Point((x2.Location.X + ((x2.Width - SelectedImageList.ImageSize.Height) / 2)),
  620.                                                                  x2.Location.Y + 4 + (textsize.Height + SelectedImageList.ImageSize.Height) / 2)
  621.                                                                  )
  622.                                                 G.DrawString(TabPages(i).Text,
  623.                                                              New Font(MyBase.Font, SelectedFontStyle),
  624.                                                              SFC,
  625.                                                              x2.Location.X + (x2.Width - textsize.Width) / 2,
  626.                                                              x2.Location.Y + (x2.Height - (textsize.Height + 4 + SelectedImageList.ImageSize.Height)) / 2
  627.                                                              )
  628.                                         End Select
  629.  
  630.  
  631.                                 End Select
  632.                             Else
  633.                                 Select Case Alignment
  634.                                     Case TabAlignment.Top
  635.                                         Select Case ImageAndTextPosition
  636.                                             Case ImageTextPosition.ImageBeforeText
  637.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  638.                                             Case ImageTextPosition.ImageAfterText
  639.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + x2.Width - ImageList.ImageSize.Width - 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  640.                                             Case ImageTextPosition.ImageAboveText
  641.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 5))
  642.                                             Case ImageTextPosition.ImageBelowText
  643.                                                 G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex),
  644.                                                           New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2), x2.Location.Y + (((x2.Height / 2 - ImageList.ImageSize.Height)) / 2) + G.MeasureString(TabPages(i).Text, MyBase.Font).Height + 5))
  645.  
  646.                                         End Select
  647.  
  648.                                     Case TabAlignment.Bottom
  649.                                         G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 4, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  650.                                     Case TabAlignment.Right
  651.                                         G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + (((x2.Height - ImageList.ImageSize.Height) / 2) - 2), x2.Location.Y + 4))
  652.                                     Case TabAlignment.Left
  653.                                         G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  654.                                 End Select
  655.                             End If
  656.                         Else
  657.                             ToogleHeaderText = True
  658.                             G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  659.  
  660.                         End If
  661.                     Catch ex As Exception
  662.                         G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  663.  
  664.                     End Try
  665.                 Else
  666.                     G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  667.  
  668.                 End If
  669.             Else
  670.                 Dim x2 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y), New Size(GetTabRect(i).Width, GetTabRect(i).Height))
  671.                 Dim TextSize As SizeF = G.MeasureString(TabPages(i).Text, MyBase.Font)
  672.                 If ImageList IsNot Nothing Then
  673.                     Try
  674.                         If ImageList.Images(TabPages(i).ImageIndex) IsNot Nothing Then
  675.                             If ToogleHeaderText = True Then
  676.                                 Select Case Alignment
  677.                                     Case TabAlignment.Top
  678.                                         Select Case ImageAndTextPosition
  679.                                             Case ImageTextPosition.ImageBeforeText
  680.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  681.                                                 G.DrawString("        " & TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  682.                                             Case ImageTextPosition.ImageAfterText
  683.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + x2.Width - ImageList.ImageSize.Width - 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  684.                                                 G.DrawString(TabPages(i).Text & "      ", MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  685.                                             Case ImageTextPosition.ImageAboveText
  686.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 5))
  687.                                                 G.DrawString(TabPages(i).Text,
  688.                                                              MyBase.Font,
  689.                                                              FC,
  690.                                                              (x2.Location.X + (x2.Width - TextSize.Width) / 2) - 2,
  691.                                                              (x2.Location.Y + x2.Height - ImageList.ImageSize.Height - 2))
  692.  
  693.                                             Case ImageTextPosition.ImageBelowText
  694.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex),
  695.                                                           New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2),
  696.                                                                     (x2.Location.Y + (x2.Height - (TextSize.Height + 4 + ImageList.ImageSize.Height)) / 2) + TextSize.Height + 5))
  697.                                                 G.DrawString(TabPages(i).Text,
  698.                                                              New Font(MyBase.Font, SelectedFontStyle),
  699.                                                              FC,
  700.                                                              (x2.Location.X + (x2.Width - TextSize.Width) / 2) - 2,
  701.                                                              (x2.Location.Y + (x2.Height - (TextSize.Height + 4 + ImageList.ImageSize.Height)) / 2))
  702.                                         End Select
  703.  
  704.                                     Case TabAlignment.Bottom
  705.                                         Select Case ImageAndTextPosition
  706.                                             Case ImageTextPosition.ImageBeforeText
  707.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 4, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) + 2))
  708.                                                 G.DrawString("        " & TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  709.                                             Case ImageTextPosition.ImageAfterText
  710.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + x2.Width - ImageList.ImageSize.Width - 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  711.                                                 G.DrawString("        " & TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  712.                                             Case ImageTextPosition.ImageAboveText
  713.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 5))
  714.                                                 G.DrawString(TabPages(i).Text,
  715.                                                              MyBase.Font,
  716.                                                              FC,
  717.                                                              (x2.Location.X + (x2.Width - TextSize.Width) / 2),
  718.                                                              (x2.Location.Y + x2.Height - ImageList.ImageSize.Height - 2))
  719.                                             Case ImageTextPosition.ImageBelowText
  720.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex),
  721.                                                           New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2),
  722.                                                                     (x2.Location.Y + (x2.Height - (TextSize.Height + 4 + ImageList.ImageSize.Height)) / 2) + TextSize.Height + 5))
  723.                                                 G.DrawString(TabPages(i).Text,
  724.                                                              New Font(MyBase.Font, SelectedFontStyle),
  725.                                                              FC,
  726.                                                              (x2.Location.X + (x2.Width - TextSize.Width) / 2) - 2,
  727.                                                              (x2.Location.Y + (x2.Height - (TextSize.Height + 4 + ImageList.ImageSize.Height)) / 2))
  728.                                         End Select
  729.                                     Case TabAlignment.Right
  730.                                         Select Case ImageAndTextPosition
  731.                                             Case ImageTextPosition.ImageBeforeText
  732.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 10, x2.Location.Y + ((x2.Height - SelectedImageList.ImageSize.Height) / 2)))
  733.                                                 G.DrawString("       " & TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  734.                                             Case ImageTextPosition.ImageAfterText
  735.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + x2.Width - ImageList.ImageSize.Width, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2)))
  736.                                                 G.DrawString(TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  737.                                             Case ImageTextPosition.ImageAboveText
  738.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  739.                                                 G.DrawString(TabPages(i).Text,
  740.                                                              MyBase.Font,
  741.                                                              FC,
  742.                                                              (x2.Location.X + (x2.Width - TextSize.Width) / 2),
  743.                                                              (x2.Location.Y + x2.Height - ImageList.ImageSize.Height))
  744.                                             Case ImageTextPosition.ImageBelowText
  745.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex),
  746.                                                        New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2),
  747.                                                                  (x2.Location.Y + (x2.Height - (TextSize.Height + 2 + ImageList.ImageSize.Height)) / 2) + TextSize.Height))
  748.                                                 G.DrawString(TabPages(i).Text,
  749.                                                              MyBase.Font,
  750.                                                              FC,
  751.                                                              (x2.Location.X + (x2.Width - TextSize.Width) / 2) - 2,
  752.                                                              (x2.Location.Y + (x2.Height - (TextSize.Height + ImageList.ImageSize.Height)) / 2) - 2)
  753.                                         End Select
  754.  
  755.                                     Case TabAlignment.Left
  756.                                         Select Case ImageAndTextPosition
  757.                                             Case ImageTextPosition.ImageBeforeText
  758.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  759.                                                 G.DrawString("       " & TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  760.                                             Case ImageTextPosition.ImageAfterText
  761.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + x2.Height - ImageList.ImageSize.Width - 2), x2.Location.Y + ((x2.Width - ImageList.ImageSize.Height) / 2) - 2))
  762.                                                 G.DrawString(TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  763.                                             Case ImageTextPosition.ImageAboveText
  764.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex),
  765.                                                             New Point((x2.Location.X + ((x2.Width - ImageList.ImageSize.Height) / 2)),
  766.                                                                       (x2.Location.Y + (x2.Width - ImageList.ImageSize.Width) / 2) - (TextSize.Height / 2)))
  767.                                                 G.DrawString(TabPages(i).Text,
  768.                                                              MyBase.Font,
  769.                                                              FC,
  770.                                                              x2.Location.X + (x2.Height - TextSize.Width) / 2,
  771.                                                              x2.Location.Y + ((x2.Width - (ImageList.ImageSize.Height + TextSize.Height)) / 2) + ImageList.ImageSize.Height
  772.                                                              )
  773.                                             Case ImageTextPosition.ImageBelowText
  774.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex),
  775.                                                        New Point((x2.Location.X + ((x2.Width - ImageList.ImageSize.Height) / 2)),
  776.                                                                  x2.Location.Y + 4 + (TextSize.Height + ImageList.ImageSize.Height) / 2)
  777.                                                                  )
  778.                                                 G.DrawString(TabPages(i).Text,
  779.                                                              MyBase.Font,
  780.                                                              FC,
  781.                                                              x2.Location.X + (x2.Width - TextSize.Width) / 2,
  782.                                                              x2.Location.Y + (x2.Height - (TextSize.Height + 4 + ImageList.ImageSize.Height)) / 2
  783.                                                              )
  784.                                         End Select
  785.  
  786.                                 End Select
  787.                             Else
  788.                                 Select Case Alignment
  789.                                     Case TabAlignment.Top
  790.                                         Select Case ImageAndTextPosition
  791.                                             Case ImageTextPosition.ImageBeforeText
  792.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  793.                                             Case ImageTextPosition.ImageAfterText
  794.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + x2.Width - ImageList.ImageSize.Width - 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  795.                                             Case ImageTextPosition.ImageAboveText
  796.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2), x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 5))
  797.                                             Case ImageTextPosition.ImageBelowText
  798.                                                 G.DrawImage(ImageList.Images(TabPages(i).ImageIndex),
  799.                                                           New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2), x2.Location.Y + (((x2.Height / 2 - ImageList.ImageSize.Height)) / 2) + G.MeasureString(TabPages(i).Text, MyBase.Font).Height + 5))
  800.  
  801.                                         End Select
  802.                                     Case TabAlignment.Bottom
  803.                                         G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 4, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  804.                                     Case TabAlignment.Right
  805.                                         G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + (((x2.Height - ImageList.ImageSize.Height) / 2) - 2), x2.Location.Y + 4))
  806.                                     Case TabAlignment.Left
  807.                                         G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
  808.                                 End Select
  809.  
  810.                             End If
  811.                         Else
  812.                             ToogleHeaderText = True
  813.                             G.DrawString(TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  814.  
  815.                         End If
  816.                     Catch ex As Exception
  817.                         G.DrawString(TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  818.  
  819.                     End Try
  820.                 Else
  821.                     G.DrawString(TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
  822.  
  823.                 End If
  824.             End If
  825.  
  826.             'draw base line under all tab
  827.             If ShowBaseLine = True Then
  828.                 Select Case Alignment
  829.                     Case TabAlignment.Top
  830.                         Using mypen As New Pen(BaseLineColor, 3)
  831.                             G.DrawLine(mypen, New Point(0, GetTabRect(i).Height), New Point(Width, GetTabRect(i).Height))
  832.                         End Using
  833.                     Case TabAlignment.Bottom
  834.                         Using mypen As New Pen(BaseLineColor, 3)
  835.                             G.DrawLine(mypen, New Point(0, Height - GetTabRect(i).Height - 1), New Point(Width, Height - GetTabRect(i).Height - 1))
  836.                         End Using
  837.                     Case TabAlignment.Left
  838.                         Using mypen As New Pen(BaseLineColor, 3)
  839.                             G.DrawLine(mypen, New Point(GetTabRect(i).Height, 0), New Point(GetTabRect(i).Height, Height))
  840.                         End Using
  841.                     Case TabAlignment.Right
  842.                         Using mypen As New Pen(BaseLineColor, 3)
  843.                             G.DrawLine(mypen, New Point(Width - GetTabRect(i).Height, 0), New Point(Width - GetTabRect(i).Height, Height))
  844.                         End Using
  845.                 End Select
  846.             End If
  847.  
  848.             'draw close button
  849.             If ShowCloseButton = True Then
  850.                 If SelectedIndex = i Then
  851.                     X3 = New Rectangle(New Point(GetTabRect(i).Location.X + GetTabRect(i).Width - 16, GetTabRect(i).Location.Y + GetTabRect(i).Height / 2 - 8), New Size(16, 16))
  852.                     Dim SelectedImg As Image
  853.                     If ImageForSelectedCloseButton = CloseButtonImage.Dark Then
  854.                         SelectedImg = My.Resources.close2
  855.                     Else
  856.                         SelectedImg = My.Resources.close1
  857.                     End If
  858.                     G.DrawImage(SelectedImg, X3.Location.X, X3.Location.Y, 16, 16)
  859.  
  860.                     If _isMouseHover Then
  861.                         If X3.IntersectsWith(_mouseRect) = True Then
  862.                             G.FillRectangle(New SolidBrush(Color.FromArgb(40, 255, 255, 255)), X3)
  863.                             G.DrawImage(SelectedImg, X3.Location.X, X3.Location.Y, 16, 16)
  864.                         End If
  865.                     End If
  866.                 Else
  867.                     X3 = New Rectangle(New Point(GetTabRect(i).Location.X + GetTabRect(i).Width - 16, GetTabRect(i).Location.Y + GetTabRect(i).Height / 2 - 8), New Size(16, 16))
  868.                     Dim Img As Image
  869.                     If ImageForCloseButton = CloseButtonImage.Dark Then
  870.                         Img = My.Resources.close2
  871.                     Else
  872.                         Img = My.Resources.close1
  873.                     End If
  874.  
  875.                     G.DrawImage(Img, X3.Location.X, X3.Location.Y, 16, 16)
  876.  
  877.                     If _isMouseHover Then
  878.                         If X3.IntersectsWith(_mouseRect) = True Then
  879.                             G.FillRectangle(New SolidBrush(Color.FromArgb(40, 255, 255, 255)), X3)
  880.                             G.DrawImage(Img, X3.Location.X, X3.Location.Y, 16, 16)
  881.                         End If
  882.                     End If
  883.                 End If
  884.  
  885.             End If
  886.  
  887.         Next
  888.  
  889.  
  890.         'XXXX dibawah ini adalah kode untuk mengaplikasikan warna ke tabcontrol XXXX
  891.         'Ini adalah kode untuk menerapkan hasil painting dengan GDI+ diatas ke
  892.         'objek Graphics dari control sehingga hasil paintingnya muncul.
  893.  
  894.  
  895.         e.Graphics.DrawImage(B, 0, 0)
  896.  
  897.         'dibawah ini adalah kode agar warna dan bitmap tidak disimpan di memory
  898.         G.Dispose() : B.Dispose() : UC.Dispose() : white.Dispose() : FC.Dispose() : HC.Dispose() : SFC.Dispose() : TC.Dispose() : ULC.Dispose()
  899.         MyBase.OnPaint(e)
  900.  
  901.     End Sub
  902. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement