Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.ComponentModel
- Imports System.Drawing.Drawing2D
- Imports System.Drawing
- Public Class MyCustomTab
- Inherits TabControl
- #Region "Enumeration"
- Enum LinePosition
- Top
- Right
- Left
- Bottom
- End Enum
- Enum ImageTextPosition
- ImageBeforeText
- ImageAfterText
- ImageBelowText
- ImageAboveText
- End Enum
- Enum CloseButtonImage
- Light
- Dark
- End Enum
- #End Region
- #Region "Declaration"
- Private selectedcolor As Color
- Private unselectedcolor As Color
- Private horizontalheaderalignment As StringAlignment
- Private verticalheaderalignment As StringAlignment
- Private headertextorientation As StringFormatFlags
- Private tabheaderfontcolor As Color
- Private _isMouseHover As Boolean = False
- Private hotcolor As Color
- Private selectedFC As Color
- Private ToogleText As Boolean = True
- Private isShowTriangle As Boolean = False
- Private _TriangleColor As Color
- Private isShowUnderline As Boolean = False
- Private _UnderlineColor As Color
- Private _UnderlineWidth As Single
- Private _ImageList2 As ImageList
- Private _SelectedFontStyle As FontStyle
- Private _LinePosition As LinePosition
- Private _ShowBaseLine As Boolean = False
- Private _BaseLineColor As Color
- Private _ImageTextPosition As ImageTextPosition
- Private _ShowCloseButton As Boolean
- Private _ImageForCloseButton As CloseButtonImage
- Private _ImageForSelectedCloseButton As CloseButtonImage
- Private X3 As Rectangle
- #End Region
- #Region " Properties "
- Dim p As PointF()
- Public Property ImageForSelectedCloseButton As CloseButtonImage
- Get
- Return _ImageForSelectedCloseButton
- End Get
- Set(value As CloseButtonImage)
- End Set
- End Property
- Public Property ImageForCloseButton As CloseButtonImage
- Get
- Return _ImageForCloseButton
- End Get
- Set(value As CloseButtonImage)
- _ImageForCloseButton = value
- Invalidate()
- End Set
- End Property
- Public Property ShowCloseButton As Boolean
- Get
- Return _ShowCloseButton
- End Get
- Set(value As Boolean)
- _ShowCloseButton = value
- Invalidate()
- End Set
- End Property
- Public Property ImageAndTextPosition As ImageTextPosition
- Get
- Return _ImageTextPosition
- End Get
- Set(value As ImageTextPosition)
- _ImageTextPosition = value
- Invalidate()
- End Set
- End Property
- Public Property ShowBaseLine As Boolean
- Get
- Return _ShowBaseLine
- End Get
- Set(value As Boolean)
- _ShowBaseLine = value
- Invalidate()
- End Set
- End Property
- Public Property BaseLineColor As Color
- Get
- Return _BaseLineColor
- End Get
- Set(value As Color)
- _BaseLineColor = value
- Invalidate()
- End Set
- End Property
- Public Property UnderlinePosition As LinePosition
- Get
- Return _LinePosition
- End Get
- Set(value As LinePosition)
- _LinePosition = value
- Invalidate()
- End Set
- End Property
- Public Property SelectedFontStyle As FontStyle
- Get
- Return _SelectedFontStyle
- End Get
- Set(value As FontStyle)
- _SelectedFontStyle = value
- Invalidate()
- End Set
- End Property
- Public Property SelectedImageList As ImageList
- Get
- Return _ImageList2
- End Get
- Set(value As ImageList)
- _ImageList2 = value
- Invalidate()
- End Set
- End Property
- Public Property UnderlineWidth As Single
- <DefaultValue(3)>
- Get
- Return _UnderlineWidth
- End Get
- Set(value As Single)
- _UnderlineWidth = value
- Invalidate()
- End Set
- End Property
- Public Property ShowUnderline As Boolean
- Get
- Return isShowUnderline
- End Get
- Set(value As Boolean)
- isShowUnderline = value
- Invalidate()
- End Set
- End Property
- Public Property UnderlineColor As Color
- Get
- Return _UnderlineColor
- End Get
- Set(value As Color)
- _UnderlineColor = value
- Invalidate()
- End Set
- End Property
- Public Property TriangleColor As Color
- Get
- Return _TriangleColor
- End Get
- Set(value As Color)
- _TriangleColor = value
- Invalidate()
- End Set
- End Property
- Public Property ToogleHeaderText As Boolean
- Get
- Return ToogleText
- End Get
- Set(value As Boolean)
- ToogleText = value
- Invalidate()
- End Set
- End Property
- Public Property ShowTriangle As Boolean
- Get
- Return isShowTriangle
- End Get
- Set(value As Boolean)
- isShowTriangle = value
- Invalidate()
- End Set
- End Property
- Public Property HotTrackColor As Color
- <DefaultValue(GetType(Color), "Black")>
- Get
- Return hotcolor
- End Get
- Set(value As Color)
- hotcolor = value
- Invalidate()
- End Set
- End Property
- Public Property SelectedFontColor As Color
- <DefaultValue(GetType(Color), "Black")>
- Get
- Return selectedFC
- End Get
- Set(value As Color)
- selectedFC = value
- Invalidate()
- End Set
- End Property
- Public Property HeaderSelectedColor As Color
- <DefaultValue(GetType(Color), "Blue")>
- Get
- Return selectedcolor
- End Get
- Set(ByVal value As Color)
- selectedcolor = value
- Invalidate()
- End Set
- End Property
- Public Property HeaderUnselectedColor As Color
- <DefaultValue(GetType(Color), "DarkBlue")>
- Get
- Return unselectedcolor
- End Get
- Set(ByVal value As Color)
- unselectedcolor = value
- Invalidate()
- End Set
- End Property
- Public Property HorizontalHeader As System.Drawing.StringAlignment
- Get
- Return horizontalheaderalignment
- End Get
- Set(ByVal value As System.Drawing.StringAlignment)
- horizontalheaderalignment = value
- Invalidate()
- End Set
- End Property
- Public Property VerticalHeader As System.Drawing.StringAlignment
- Get
- Return verticalheaderalignment
- End Get
- Set(ByVal value As System.Drawing.StringAlignment)
- verticalheaderalignment = value
- Invalidate()
- End Set
- End Property
- Public Property HeaderLayout As System.Drawing.StringFormatFlags
- Get
- Return headertextorientation
- End Get
- Set(ByVal value As System.Drawing.StringFormatFlags)
- headertextorientation = value
- Invalidate()
- End Set
- End Property
- Public Property HeaderFontColor As Color
- <DefaultValue(GetType(Color), "Black")>
- Get
- Return tabheaderfontcolor
- End Get
- Set(ByVal value As Color)
- tabheaderfontcolor = value
- Invalidate()
- End Set
- End Property
- Public Overrides ReadOnly Property DisplayRectangle As System.Drawing.Rectangle
- Get
- Dim rc As Rectangle = MyBase.DisplayRectangle
- rc.Offset(0, 0)
- rc.Width += 1
- rc.Inflate(4, 4)
- Return rc
- End Get
- End Property
- #End Region
- Sub New()
- InitializeComponent()
- SetStyle(ControlStyles.AllPaintingInWmPaint _
- Or ControlStyles.OptimizedDoubleBuffer _
- Or ControlStyles.ResizeRedraw _
- Or ControlStyles.UserPaint _
- Or ControlStyles.SupportsTransparentBackColor, True)
- DoubleBuffered = True
- HeaderFontColor = Color.Black
- SelectedFontColor = Color.Black
- HeaderSelectedColor = Color.White
- HeaderUnselectedColor = Color.AliceBlue
- HotTrackColor = Color.FromArgb(40, 0, 0, 0)
- UnderlineWidth = 3
- SelectedFontStyle = FontStyle.Bold
- _ImageTextPosition = ImageTextPosition.ImageBeforeText
- ImageForCloseButton = CloseButtonImage.Dark
- ImageForSelectedCloseButton = CloseButtonImage.Dark
- ShowCloseButton = False
- End Sub
- Private _mouseRect As Rectangle
- Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
- MyBase.OnMouseMove(e)
- _isMouseHover = True
- _mouseRect = New Rectangle(e.X, e.Y, 1, 1)
- Invalidate()
- End Sub
- Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
- MyBase.OnMouseLeave(e)
- _isMouseHover = False
- Invalidate()
- End Sub
- Protected Overrides Sub OnClick(e As EventArgs)
- MyBase.OnClick(e)
- For i = 0 To TabCount - 1
- MsgBox(GetTabRect(i).ToString & " " & X3.ToString)
- If GetTabRect(i).Contains(X3) = True Then
- If _mouseRect.IntersectsWith(X3) = True Then
- TabPages.RemoveAt(i)
- End If
- End If
- Next
- End Sub
- Protected Overrides Sub CreateHandle()
- MyBase.CreateHandle()
- End Sub
- Protected Overrides Sub OnPaintBackground(ByVal pevent As PaintEventArgs)
- MyBase.OnPaintBackground(pevent)
- Me.InvokePaintBackground(Me.Parent, pevent)
- Me.InvokePaint(Me.Parent, pevent)
- End Sub
- Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
- Dim UC As New SolidBrush(unselectedcolor)
- Dim white As New SolidBrush(selectedcolor)
- Dim FC As New SolidBrush(HeaderFontColor)
- Dim HC As New SolidBrush(hotcolor)
- Dim SFC As New SolidBrush(SelectedFontColor)
- Dim TC As New SolidBrush(TriangleColor)
- Dim ULC As New SolidBrush(UnderlineColor)
- Dim B As New Bitmap(Width, Height)
- Dim G As Graphics = Graphics.FromImage(B)
- G.Clear(Color.Transparent)
- For i = 0 To TabCount - 1
- Dim tabrectangel As Rectangle = GetTabRect(i)
- tabrectangel.Inflate(1, 1)
- If SelectedIndex = i Then
- '//jika tab dipilih
- G.FillRectangle(white, tabrectangel)
- G.SmoothingMode = SmoothingMode.HighQuality
- If _isMouseHover Then
- If tabrectangel.IntersectsWith(_mouseRect) Then
- G.FillRectangle(HC, tabrectangel)
- End If
- End If
- Else
- '//jika tab tidak dipilih
- G.FillRectangle(UC, tabrectangel)
- G.SmoothingMode = SmoothingMode.HighQuality
- If _isMouseHover Then
- If tabrectangel.IntersectsWith(_mouseRect) Then
- G.FillRectangle(HC, tabrectangel)
- End If
- End If
- End If
- If SelectedIndex = i Then
- 'draw line in each tab
- If isShowUnderline = True And _UnderlineWidth > 0 Then
- Select Case Alignment
- Case TabAlignment.Left
- Select Case UnderlinePosition
- Case LinePosition.Top
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(GetTabRect(i).Location.X - 1, GetTabRect(i).Location.Y),
- New Point(GetTabRect(i).Location.X + GetTabRect(i).Height, GetTabRect(i).Location.Y))
- Case LinePosition.Bottom
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(GetTabRect(i).Location.X - 1, GetTabRect(i).Location.Y + GetTabRect(i).Width - 2),
- New Point(GetTabRect(i).Location.X + GetTabRect(i).Height, GetTabRect(i).Location.Y + GetTabRect(i).Width - 2))
- Case LinePosition.Right
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(GetTabRect(i).Location.X + GetTabRect(i).Height - 2, GetTabRect(i).Location.Y),
- New Point(GetTabRect(i).Location.X + GetTabRect(i).Height - 2, GetTabRect(i).Location.Y + GetTabRect(i).Width))
- Case LinePosition.Left
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(GetTabRect(i).Location.X - 1, GetTabRect(i).Location.Y),
- New Point(GetTabRect(i).Location.X - 1, GetTabRect(i).Location.Y + GetTabRect(i).Width))
- End Select
- Case TabAlignment.Right
- Select Case UnderlinePosition
- Case LinePosition.Top
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(Me.Width - GetTabRect(i).Height, GetTabRect(i).Location.Y),
- New Point(Me.Width, GetTabRect(i).Location.Y))
- Case LinePosition.Bottom
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(Me.Width - GetTabRect(i).Height, GetTabRect(i).Location.Y + GetTabRect(i).Width - 2),
- New Point(Me.Width, GetTabRect(i).Location.Y + GetTabRect(i).Width - 2))
- Case LinePosition.Right
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(Me.Width - 2, GetTabRect(i).Location.Y),
- New Point(Me.Width - 2, GetTabRect(i).Location.Y + GetTabRect(i).Width))
- Case LinePosition.Left
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(Me.Width - GetTabRect(i).Height, GetTabRect(i).Location.Y),
- New Point(Me.Width - GetTabRect(i).Height, GetTabRect(i).Location.Y + GetTabRect(i).Width))
- End Select
- Case TabAlignment.Top
- Select Case UnderlinePosition
- Case LinePosition.Top
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y),
- New Point(GetTabRect(i).Location.X + GetTabRect(i).Width, GetTabRect(i).Location.Y))
- Case LinePosition.Bottom
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y + GetTabRect(i).Height - 2),
- New Point(GetTabRect(i).Location.X + GetTabRect(i).Width, GetTabRect(i).Location.Y + GetTabRect(i).Height - 2))
- Case LinePosition.Right
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(GetTabRect(i).Location.X + GetTabRect(i).Width - 2, GetTabRect(i).Location.Y),
- New Point(GetTabRect(i).Location.X + GetTabRect(i).Width - 2, GetTabRect(i).Location.Y + GetTabRect(i).Height - 2))
- Case LinePosition.Left
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y),
- New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y + GetTabRect(i).Height - 2))
- End Select
- Case TabAlignment.Bottom
- Select Case UnderlinePosition
- Case LinePosition.Top
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y + 2),
- New Point(GetTabRect(i).Location.X + GetTabRect(i).Width, GetTabRect(i).Location.Y + 2))
- Case LinePosition.Bottom
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y + GetTabRect(i).Height - 2),
- New Point(GetTabRect(i).Location.X + GetTabRect(i).Width, GetTabRect(i).Location.Y + GetTabRect(i).Height - 2))
- Case LinePosition.Right
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(GetTabRect(i).Location.X + GetTabRect(i).Width - 2, GetTabRect(i).Location.Y),
- New Point(GetTabRect(i).Location.X + GetTabRect(i).Width - 2, GetTabRect(i).Location.Y + GetTabRect(i).Width - 2))
- Case LinePosition.Left
- G.DrawLine(New Pen(ULC, _UnderlineWidth),
- New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y),
- New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y + GetTabRect(i).Width - 2))
- End Select
- End Select
- ElseIf isShowUnderline = True And _UnderlineWidth <= 0 Then
- If Me.DesignMode = True Then
- MsgBox("Value must be higher than 0", MsgBoxStyle.Exclamation)
- isShowUnderline = False
- _UnderlineWidth = 3
- End If
- End If
- 'draw pointed triangle
- If isShowTriangle = True Then
- Select Case Me.Alignment
- Case TabAlignment.Left
- G.SmoothingMode = SmoothingMode.AntiAlias
- Dim p() As Point = {New Point(GetTabRect(i).Height - 7, GetTabRect(i).Location.Y + (GetTabRect(i).Width / 2)),
- New Point(GetTabRect(i).Height + 5, GetTabRect(i).Location.Y + (GetTabRect(i).Width / 2) - 10),
- New Point(GetTabRect(i).Height + 5, GetTabRect(i).Location.Y + (GetTabRect(i).Width / 2) + 10)}
- G.FillPolygon(TC, p)
- G.DrawPolygon(New Pen(TC), p)
- Case TabAlignment.Right
- G.SmoothingMode = SmoothingMode.AntiAlias
- Dim p() As Point = {New Point(Me.Width - GetTabRect(i).Height + 7, GetTabRect(i).Location.Y + (GetTabRect(i).Width / 2)),
- New Point(Me.Width - GetTabRect(i).Height - 3, GetTabRect(i).Location.Y + (GetTabRect(i).Width / 2) - 10),
- New Point(Me.Width - GetTabRect(i).Height - 3, GetTabRect(i).Location.Y + (GetTabRect(i).Width / 2) + 10)}
- G.FillPolygon(TC, p)
- G.DrawPolygon(New Pen(TC), p)
- Case TabAlignment.Top
- G.SmoothingMode = SmoothingMode.AntiAlias
- Dim p() As Point = {New Point(GetTabRect(i).Location.X + (GetTabRect(i).Width / 2), GetTabRect(i).Height - 7),
- New Point(GetTabRect(i).Location.X + (GetTabRect(i).Width / 2) - 10, GetTabRect(i).Location.Y + GetTabRect(i).Height),
- New Point(GetTabRect(i).Location.X + (GetTabRect(i).Width / 2) + 10, GetTabRect(i).Location.Y + GetTabRect(i).Height)}
- G.FillPolygon(TC, p)
- G.DrawPolygon(New Pen(TC), p)
- Case TabAlignment.Bottom
- G.SmoothingMode = SmoothingMode.AntiAlias
- Dim p() As Point = {New Point(GetTabRect(i).Location.X + (GetTabRect(i).Width / 2), Me.Height - GetTabRect(i).Height + 7),
- New Point(GetTabRect(i).Location.X + (GetTabRect(i).Width / 2) - 10, GetTabRect(i).Location.Y - 2),
- New Point(GetTabRect(i).Location.X + (GetTabRect(i).Width / 2) + 10, GetTabRect(i).Location.Y - 2)}
- G.FillPolygon(TC, p)
- G.DrawPolygon(New Pen(TC), p)
- End Select
- End If
- 'Draw image
- Dim x2 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y), New Size(GetTabRect(i).Width, GetTabRect(i).Height))
- Dim textsize As SizeF = G.MeasureString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle))
- If SelectedImageList IsNot Nothing Then
- Try
- If SelectedImageList.Images(TabPages(i).ImageIndex) IsNot Nothing Then
- If ToogleHeaderText = True Then
- Select Case Alignment
- Case TabAlignment.Top
- Select Case ImageAndTextPosition
- Case ImageTextPosition.ImageBeforeText
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
- G.DrawString(" " & TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAfterText
- 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))
- G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAboveText
- 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))
- G.DrawString(TabPages(i).Text,
- New Font(MyBase.Font, SelectedFontStyle),
- SFC,
- (x2.Location.X + (x2.Width - textsize.Width) / 2) - 2,
- (x2.Location.Y + x2.Height - SelectedImageList.ImageSize.Height - 2))
- Case ImageTextPosition.ImageBelowText
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex),
- New Point((x2.Location.X + (x2.Width - SelectedImageList.ImageSize.Width) / 2),
- (x2.Location.Y + (x2.Height - (textsize.Height + 4 + SelectedImageList.ImageSize.Height)) / 2) + textsize.Height + 5))
- G.DrawString(TabPages(i).Text,
- New Font(MyBase.Font, SelectedFontStyle),
- SFC,
- (x2.Location.X + (x2.Width - textsize.Width) / 2) - 2,
- (x2.Location.Y + (x2.Height - (textsize.Height + 4 + SelectedImageList.ImageSize.Height)) / 2))
- End Select
- Case TabAlignment.Bottom
- Select Case ImageAndTextPosition
- Case ImageTextPosition.ImageBeforeText
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 4, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) + 2))
- G.DrawString(" " & TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAfterText
- 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))
- G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAboveText
- 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))
- G.DrawString(TabPages(i).Text,
- New Font(MyBase.Font, SelectedFontStyle),
- SFC,
- (x2.Location.X + (x2.Width - textsize.Width) / 2) - 2,
- (x2.Location.Y + x2.Height - ImageList.ImageSize.Height - 2))
- Case ImageTextPosition.ImageBelowText
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex),
- New Point((x2.Location.X + (x2.Width - SelectedImageList.ImageSize.Width) / 2),
- (x2.Location.Y + (x2.Height - (textsize.Height + 4 + SelectedImageList.ImageSize.Height)) / 2) + textsize.Height))
- G.DrawString(TabPages(i).Text,
- New Font(MyBase.Font, SelectedFontStyle),
- SFC,
- (x2.Location.X + (x2.Width - textsize.Width) / 2) - 2,
- (x2.Location.Y + (x2.Height - (textsize.Height + 4 + SelectedImageList.ImageSize.Height)) / 2))
- End Select
- Case TabAlignment.Right
- Select Case ImageAndTextPosition
- Case ImageTextPosition.ImageBeforeText
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 10, x2.Location.Y + ((x2.Height - SelectedImageList.ImageSize.Height) / 2)))
- G.DrawString(" " & TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAfterText
- 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)))
- G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAboveText
- 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))
- G.DrawString(TabPages(i).Text,
- New Font(MyBase.Font, SelectedFontStyle),
- SFC,
- (x2.Location.X + (x2.Width - textsize.Width) / 2),
- (x2.Location.Y + x2.Height - SelectedImageList.ImageSize.Height - 2))
- Case ImageTextPosition.ImageBelowText
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex),
- New Point((x2.Location.X + (x2.Width - SelectedImageList.ImageSize.Width) / 2),
- (x2.Location.Y + (x2.Height - (textsize.Height + 2 + SelectedImageList.ImageSize.Height)) / 2) + textsize.Height))
- G.DrawString(TabPages(i).Text,
- New Font(MyBase.Font, SelectedFontStyle),
- SFC,
- (x2.Location.X + (x2.Width - textsize.Width) / 2) - 2,
- (x2.Location.Y + (x2.Height - (textsize.Height + SelectedImageList.ImageSize.Height)) / 2) - 2)
- End Select
- Case TabAlignment.Left
- Select Case ImageAndTextPosition
- Case ImageTextPosition.ImageBeforeText
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
- G.DrawString(" " & TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAfterText
- 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))
- G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAboveText
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex),
- New Point((x2.Location.X + ((x2.Width - SelectedImageList.ImageSize.Height) / 2)),
- (x2.Location.Y + (x2.Width - SelectedImageList.ImageSize.Width) / 2) - (textsize.Height / 2)))
- G.DrawString(TabPages(i).Text,
- New Font(MyBase.Font, SelectedFontStyle),
- SFC,
- x2.Location.X + (x2.Height - textsize.Width) / 2,
- x2.Location.Y + ((x2.Width - (SelectedImageList.ImageSize.Height + textsize.Height)) / 2) + SelectedImageList.ImageSize.Height
- )
- Case ImageTextPosition.ImageBelowText
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex),
- New Point((x2.Location.X + ((x2.Width - SelectedImageList.ImageSize.Height) / 2)),
- x2.Location.Y + 4 + (textsize.Height + SelectedImageList.ImageSize.Height) / 2)
- )
- G.DrawString(TabPages(i).Text,
- New Font(MyBase.Font, SelectedFontStyle),
- SFC,
- x2.Location.X + (x2.Width - textsize.Width) / 2,
- x2.Location.Y + (x2.Height - (textsize.Height + 4 + SelectedImageList.ImageSize.Height)) / 2
- )
- End Select
- End Select
- Else
- Select Case Alignment
- Case TabAlignment.Top
- Select Case ImageAndTextPosition
- Case ImageTextPosition.ImageBeforeText
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
- Case ImageTextPosition.ImageAfterText
- 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))
- Case ImageTextPosition.ImageAboveText
- 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))
- Case ImageTextPosition.ImageBelowText
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex),
- 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))
- End Select
- Case TabAlignment.Bottom
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 4, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
- Case TabAlignment.Right
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + (((x2.Height - ImageList.ImageSize.Height) / 2) - 2), x2.Location.Y + 4))
- Case TabAlignment.Left
- G.DrawImage(SelectedImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
- End Select
- End If
- Else
- ToogleHeaderText = True
- G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- End If
- Catch ex As Exception
- G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- End Try
- Else
- G.DrawString(TabPages(i).Text, New Font(MyBase.Font, SelectedFontStyle), SFC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- End If
- Else
- Dim x2 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y), New Size(GetTabRect(i).Width, GetTabRect(i).Height))
- Dim TextSize As SizeF = G.MeasureString(TabPages(i).Text, MyBase.Font)
- If ImageList IsNot Nothing Then
- Try
- If ImageList.Images(TabPages(i).ImageIndex) IsNot Nothing Then
- If ToogleHeaderText = True Then
- Select Case Alignment
- Case TabAlignment.Top
- Select Case ImageAndTextPosition
- Case ImageTextPosition.ImageBeforeText
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
- G.DrawString(" " & TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAfterText
- 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))
- G.DrawString(TabPages(i).Text & " ", MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAboveText
- 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))
- G.DrawString(TabPages(i).Text,
- MyBase.Font,
- FC,
- (x2.Location.X + (x2.Width - TextSize.Width) / 2) - 2,
- (x2.Location.Y + x2.Height - ImageList.ImageSize.Height - 2))
- Case ImageTextPosition.ImageBelowText
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex),
- New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2),
- (x2.Location.Y + (x2.Height - (TextSize.Height + 4 + ImageList.ImageSize.Height)) / 2) + TextSize.Height + 5))
- G.DrawString(TabPages(i).Text,
- New Font(MyBase.Font, SelectedFontStyle),
- FC,
- (x2.Location.X + (x2.Width - TextSize.Width) / 2) - 2,
- (x2.Location.Y + (x2.Height - (TextSize.Height + 4 + ImageList.ImageSize.Height)) / 2))
- End Select
- Case TabAlignment.Bottom
- Select Case ImageAndTextPosition
- Case ImageTextPosition.ImageBeforeText
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 4, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) + 2))
- G.DrawString(" " & TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAfterText
- 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))
- G.DrawString(" " & TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAboveText
- 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))
- G.DrawString(TabPages(i).Text,
- MyBase.Font,
- FC,
- (x2.Location.X + (x2.Width - TextSize.Width) / 2),
- (x2.Location.Y + x2.Height - ImageList.ImageSize.Height - 2))
- Case ImageTextPosition.ImageBelowText
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex),
- New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2),
- (x2.Location.Y + (x2.Height - (TextSize.Height + 4 + ImageList.ImageSize.Height)) / 2) + TextSize.Height + 5))
- G.DrawString(TabPages(i).Text,
- New Font(MyBase.Font, SelectedFontStyle),
- FC,
- (x2.Location.X + (x2.Width - TextSize.Width) / 2) - 2,
- (x2.Location.Y + (x2.Height - (TextSize.Height + 4 + ImageList.ImageSize.Height)) / 2))
- End Select
- Case TabAlignment.Right
- Select Case ImageAndTextPosition
- Case ImageTextPosition.ImageBeforeText
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 10, x2.Location.Y + ((x2.Height - SelectedImageList.ImageSize.Height) / 2)))
- G.DrawString(" " & TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAfterText
- 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)))
- G.DrawString(TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAboveText
- 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))
- G.DrawString(TabPages(i).Text,
- MyBase.Font,
- FC,
- (x2.Location.X + (x2.Width - TextSize.Width) / 2),
- (x2.Location.Y + x2.Height - ImageList.ImageSize.Height))
- Case ImageTextPosition.ImageBelowText
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex),
- New Point((x2.Location.X + (x2.Width - ImageList.ImageSize.Width) / 2),
- (x2.Location.Y + (x2.Height - (TextSize.Height + 2 + ImageList.ImageSize.Height)) / 2) + TextSize.Height))
- G.DrawString(TabPages(i).Text,
- MyBase.Font,
- FC,
- (x2.Location.X + (x2.Width - TextSize.Width) / 2) - 2,
- (x2.Location.Y + (x2.Height - (TextSize.Height + ImageList.ImageSize.Height)) / 2) - 2)
- End Select
- Case TabAlignment.Left
- Select Case ImageAndTextPosition
- Case ImageTextPosition.ImageBeforeText
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
- G.DrawString(" " & TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAfterText
- 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))
- G.DrawString(TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- Case ImageTextPosition.ImageAboveText
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex),
- New Point((x2.Location.X + ((x2.Width - ImageList.ImageSize.Height) / 2)),
- (x2.Location.Y + (x2.Width - ImageList.ImageSize.Width) / 2) - (TextSize.Height / 2)))
- G.DrawString(TabPages(i).Text,
- MyBase.Font,
- FC,
- x2.Location.X + (x2.Height - TextSize.Width) / 2,
- x2.Location.Y + ((x2.Width - (ImageList.ImageSize.Height + TextSize.Height)) / 2) + ImageList.ImageSize.Height
- )
- Case ImageTextPosition.ImageBelowText
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex),
- New Point((x2.Location.X + ((x2.Width - ImageList.ImageSize.Height) / 2)),
- x2.Location.Y + 4 + (TextSize.Height + ImageList.ImageSize.Height) / 2)
- )
- G.DrawString(TabPages(i).Text,
- MyBase.Font,
- FC,
- x2.Location.X + (x2.Width - TextSize.Width) / 2,
- x2.Location.Y + (x2.Height - (TextSize.Height + 4 + ImageList.ImageSize.Height)) / 2
- )
- End Select
- End Select
- Else
- Select Case Alignment
- Case TabAlignment.Top
- Select Case ImageAndTextPosition
- Case ImageTextPosition.ImageBeforeText
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
- Case ImageTextPosition.ImageAfterText
- 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))
- Case ImageTextPosition.ImageAboveText
- 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))
- Case ImageTextPosition.ImageBelowText
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex),
- 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))
- End Select
- Case TabAlignment.Bottom
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 4, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
- Case TabAlignment.Right
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + (((x2.Height - ImageList.ImageSize.Height) / 2) - 2), x2.Location.Y + 4))
- Case TabAlignment.Left
- G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 3, x2.Location.Y + ((x2.Height - ImageList.ImageSize.Height) / 2) - 2))
- End Select
- End If
- Else
- ToogleHeaderText = True
- G.DrawString(TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- End If
- Catch ex As Exception
- G.DrawString(TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- End Try
- Else
- G.DrawString(TabPages(i).Text, MyBase.Font, FC, x2, New StringFormat With {.LineAlignment = verticalheaderalignment, .Alignment = horizontalheaderalignment})
- End If
- End If
- 'draw base line under all tab
- If ShowBaseLine = True Then
- Select Case Alignment
- Case TabAlignment.Top
- Using mypen As New Pen(BaseLineColor, 3)
- G.DrawLine(mypen, New Point(0, GetTabRect(i).Height), New Point(Width, GetTabRect(i).Height))
- End Using
- Case TabAlignment.Bottom
- Using mypen As New Pen(BaseLineColor, 3)
- G.DrawLine(mypen, New Point(0, Height - GetTabRect(i).Height - 1), New Point(Width, Height - GetTabRect(i).Height - 1))
- End Using
- Case TabAlignment.Left
- Using mypen As New Pen(BaseLineColor, 3)
- G.DrawLine(mypen, New Point(GetTabRect(i).Height, 0), New Point(GetTabRect(i).Height, Height))
- End Using
- Case TabAlignment.Right
- Using mypen As New Pen(BaseLineColor, 3)
- G.DrawLine(mypen, New Point(Width - GetTabRect(i).Height, 0), New Point(Width - GetTabRect(i).Height, Height))
- End Using
- End Select
- End If
- 'draw close button
- If ShowCloseButton = True Then
- If SelectedIndex = i Then
- 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))
- Dim SelectedImg As Image
- If ImageForSelectedCloseButton = CloseButtonImage.Dark Then
- SelectedImg = My.Resources.close2
- Else
- SelectedImg = My.Resources.close1
- End If
- G.DrawImage(SelectedImg, X3.Location.X, X3.Location.Y, 16, 16)
- If _isMouseHover Then
- If X3.IntersectsWith(_mouseRect) = True Then
- G.FillRectangle(New SolidBrush(Color.FromArgb(40, 255, 255, 255)), X3)
- G.DrawImage(SelectedImg, X3.Location.X, X3.Location.Y, 16, 16)
- End If
- End If
- Else
- 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))
- Dim Img As Image
- If ImageForCloseButton = CloseButtonImage.Dark Then
- Img = My.Resources.close2
- Else
- Img = My.Resources.close1
- End If
- G.DrawImage(Img, X3.Location.X, X3.Location.Y, 16, 16)
- If _isMouseHover Then
- If X3.IntersectsWith(_mouseRect) = True Then
- G.FillRectangle(New SolidBrush(Color.FromArgb(40, 255, 255, 255)), X3)
- G.DrawImage(Img, X3.Location.X, X3.Location.Y, 16, 16)
- End If
- End If
- End If
- End If
- Next
- 'XXXX dibawah ini adalah kode untuk mengaplikasikan warna ke tabcontrol XXXX
- 'Ini adalah kode untuk menerapkan hasil painting dengan GDI+ diatas ke
- 'objek Graphics dari control sehingga hasil paintingnya muncul.
- e.Graphics.DrawImage(B, 0, 0)
- 'dibawah ini adalah kode agar warna dan bitmap tidak disimpan di memory
- G.Dispose() : B.Dispose() : UC.Dispose() : white.Dispose() : FC.Dispose() : HC.Dispose() : SFC.Dispose() : TC.Dispose() : ULC.Dispose()
- MyBase.OnPaint(e)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement