Advertisement
dwart420

Tab

May 30th, 2012
8,234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 8.57 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2.  
  3. Class DotNetBarTabcontrol
  4.     Inherits TabControl
  5.     Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
  6.         Dim P As GraphicsPath = New GraphicsPath()
  7.         Dim ArcRectangleWidth As Integer = Curve * 2
  8.         P.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  9.         P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  10.         P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  11.         P.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  12.         P.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
  13.         Return P
  14.     End Function
  15.     Public Function RoundRect(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal Curve As Integer) As GraphicsPath
  16.         Dim Rectangle As Rectangle = New Rectangle(X, Y, Width, Height)
  17.         Dim P As GraphicsPath = New GraphicsPath()
  18.         Dim ArcRectangleWidth As Integer = Curve * 2
  19.         P.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  20.         P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  21.         P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  22.         P.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  23.         P.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
  24.         Return P
  25.     End Function
  26.     Sub New()
  27.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
  28.         DoubleBuffered = True
  29.         SizeMode = TabSizeMode.Fixed
  30.         ItemSize = New Size(35, 85)
  31.     End Sub
  32.     Protected Overrides Sub CreateHandle()
  33.         MyBase.CreateHandle()
  34.         Alignment = TabAlignment.Left
  35.     End Sub
  36.  
  37.     Function ToPen(ByVal color As Color) As Pen
  38.         Return New Pen(color)
  39.     End Function
  40.  
  41.     Function ToBrush(ByVal color As Color) As Brush
  42.         Return New SolidBrush(color)
  43.     End Function
  44.  
  45.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  46.         Dim B As New Bitmap(Width, Height)
  47.         Dim G As Graphics = Graphics.FromImage(B)
  48.         Try : SelectedTab.BackColor = Color.White : Catch : End Try
  49.         G.Clear(Parent.FindForm.BackColor)
  50.         G.FillRectangle(New SolidBrush(Color.FromArgb(96, 110, 121)), New Rectangle(0, 0, ItemSize.Height + 4, Height))
  51.         For i = 0 To TabCount - 1
  52.             If i = SelectedIndex Then
  53.                 Dim x2 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), New Size(GetTabRect(i).Width + 3, GetTabRect(i).Height - 1))
  54.                 Dim myBlend As New ColorBlend()
  55.                 myBlend.Colors = {Color.FromArgb(96, 110, 121), Color.FromArgb(96, 110, 121), Color.FromArgb(96, 110, 121)}
  56.                 myBlend.Positions = {0.0F, 0.5F, 1.0F}
  57.                 Dim lgBrush As New LinearGradientBrush(x2, Color.Black, Color.Black, 90.0F)
  58.                 lgBrush.InterpolationColors = myBlend
  59.                 G.FillRectangle(lgBrush, x2)
  60.                 G.DrawRectangle(New Pen(Color.FromArgb(96, 110, 121)), x2)
  61.                 Dim tabRect As New Rectangle(GetTabRect(i).Location.X + 4, GetTabRect(i).Location.Y + 2, GetTabRect(i).Size.Width + 10, GetTabRect(i).Size.Height - 11)
  62.                 G.FillPath(New SolidBrush(Color.FromArgb(80, 90, 100)), RoundRect(tabRect, 5))
  63.                 G.DrawPath(New Pen(Color.FromArgb(67, 77, 87)), RoundRect(New Rectangle(tabRect.X + 1, tabRect.Y + 1, tabRect.Width - 1, tabRect.Height - 2), 5))
  64.                 G.DrawPath(New Pen(Color.FromArgb(115, 125, 135)), RoundRect(tabRect, 5))
  65.  
  66.                 G.SmoothingMode = SmoothingMode.HighQuality
  67.                 'Dim p() As Point = {New Point(ItemSize.Height - 3, GetTabRect(i).Location.Y + 20), New Point(ItemSize.Height + 4, GetTabRect(i).Location.Y + 14), New Point(ItemSize.Height + 4, GetTabRect(i).Location.Y + 27)}
  68.                 'G.FillPolygon(Brushes.White, p)
  69.  
  70.                 If ImageList IsNot Nothing Then
  71.                     Try
  72.                         If ImageList.Images(TabPages(i).ImageIndex) IsNot Nothing Then
  73.  
  74.                             G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 8, x2.Location.Y + 6))
  75.                             G.DrawString("      " & TabPages(i).Text.ToUpper, New Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
  76.                         Else
  77.                             G.DrawString(TabPages(i).Text.ToUpper, New Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
  78.                         End If
  79.                     Catch ex As Exception
  80.                         G.DrawString(TabPages(i).Text.ToUpper, New Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
  81.                     End Try
  82.                 Else
  83.                     G.DrawString(TabPages(i).Text.ToUpper, New Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
  84.                 End If
  85.  
  86.                 G.DrawLine(New Pen(Color.FromArgb(96, 110, 121)), New Point(x2.Location.X - 1, x2.Location.Y - 1), New Point(x2.Location.X, x2.Location.Y))
  87.                 G.DrawLine(New Pen(Color.FromArgb(96, 110, 121)), New Point(x2.Location.X - 1, x2.Bottom - 1), New Point(x2.Location.X, x2.Bottom))
  88.             Else
  89.                 Dim x2 As Rectangle = New Rectangle(New Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), New Size(GetTabRect(i).Width + 3, GetTabRect(i).Height + 1))
  90.                 G.FillRectangle(New SolidBrush(Color.FromArgb(96, 110, 121)), x2)
  91.                 G.DrawLine(New Pen(Color.FromArgb(96, 110, 121)), New Point(x2.Right, x2.Top), New Point(x2.Right, x2.Bottom))
  92.                 If ImageList IsNot Nothing Then
  93.                     Try
  94.                         If ImageList.Images(TabPages(i).ImageIndex) IsNot Nothing Then
  95.                             G.DrawImage(ImageList.Images(TabPages(i).ImageIndex), New Point(x2.Location.X + 8, x2.Location.Y + 6))
  96.                             G.DrawString("      " & TabPages(i).Text, Font, Brushes.White, x2, New StringFormat With {.LineAlignment = StringAlignment.Near, .Alignment = StringAlignment.Near})
  97.                         Else
  98.                             G.DrawString(TabPages(i).Text.ToUpper, New Font(Font.FontFamily, Font.Size, FontStyle.Bold), New SolidBrush(Color.FromArgb(210, 220, 230)), x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
  99.                         End If
  100.                     Catch ex As Exception
  101.                         G.DrawString(TabPages(i).Text.ToUpper, New Font(Font.FontFamily, Font.Size, FontStyle.Bold), New SolidBrush(Color.FromArgb(210, 220, 230)), x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
  102.                     End Try
  103.                 Else
  104.                     G.DrawString(TabPages(i).Text.ToUpper, New Font(Font.FontFamily, Font.Size, FontStyle.Bold), New SolidBrush(Color.FromArgb(210, 220, 230)), x2, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
  105.                 End If
  106.             End If
  107.             G.FillPath(Brushes.White, RoundRect(New Rectangle(86, 0, Width - 89, Height - 3), 5))
  108.             G.DrawPath(New Pen(Color.FromArgb(65, 75, 85)), RoundRect(New Rectangle(86, 0, Width - 89, Height - 3), 5))
  109.         Next
  110.  
  111.         e.Graphics.DrawImage(B.Clone, 0, 0)
  112.         G.Dispose() : B.Dispose()
  113.     End Sub
  114. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement