Advertisement
Guest User

Custom Tab Control

a guest
Jul 5th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.21 KB | None | 0 0
  1. ' Créé par AeroRev9.
  2. ' Custom Tab Control.
  3.  
  4. Imports System.Drawing.Drawing2D
  5. Imports System.Drawing.Text
  6.  
  7. Module Helpers
  8.  
  9.     Public Enum MouseState As Byte
  10.         None = 0
  11.         Over = 1
  12.         Down = 2
  13.     End Enum
  14.  
  15.     Public Sub CenterString(G As Graphics, text As String, font As Font, brush As Brush, rect As Rectangle)
  16.  
  17.         Dim textSize As SizeF = G.MeasureString(text, font)
  18.         Dim textX As Integer = rect.X + (rect.Width / 2) - (textSize.Width / 2)
  19.         Dim textY As Integer = rect.Y + (rect.Height / 2) - (textSize.Height / 2)
  20.  
  21.         G.DrawString(text, font, brush, textX, textY + 1)
  22.  
  23.     End Sub
  24.  
  25.     Public Sub RoundRect(ByVal G As Graphics,
  26.                           ByVal X As Integer,
  27.                           ByVal Y As Integer,
  28.                           ByVal Width As Integer,
  29.                           ByVal Height As Integer,
  30.                           ByVal Curve As Integer,
  31.                           ByVal Draw As Color)
  32.  
  33.  
  34.         Dim BaseRect As New RectangleF(X, Y, Width,
  35.                                   Height)
  36.         Dim ArcRect As New RectangleF(BaseRect.Location,
  37.                               New SizeF(Curve, Curve))
  38.  
  39.         G.DrawArc(New Pen(Draw), ArcRect, 180, 90)
  40.         G.DrawLine(New Pen(Draw), X + CInt(Curve / 2),
  41.                          Y,
  42.                          Y + Width - CInt(Curve / 2),
  43.                          Y)
  44.  
  45.         ArcRect.X = BaseRect.Right - Curve
  46.         G.DrawArc(New Pen(Draw), ArcRect, 270, 90)
  47.         G.DrawLine(New Pen(Draw), X + Width,
  48.                          Y + CInt(Curve / 2),
  49.                          X + Width,
  50.                          Y + Height - CInt(Curve / 2))
  51.  
  52.         ArcRect.Y = BaseRect.Bottom - Curve
  53.         G.DrawArc(New Pen(Draw), ArcRect, 0, 90)
  54.         G.DrawLine(New Pen(Draw), X + CInt(Curve / 2),
  55.                          Y + Height,
  56.                          X + Width - CInt(Curve / 2),
  57.                          Y + Height)
  58.  
  59.         ArcRect.X = BaseRect.Left
  60.         G.DrawArc(New Pen(Draw), ArcRect, 90, 90)
  61.         G.DrawLine(New Pen(Draw),
  62.                          X, Y + CInt(Curve / 2),
  63.                          X,
  64.                          Y + Height - CInt(Curve / 2))
  65.  
  66.     End Sub
  67.  
  68. End Module
  69.  
  70. Class CustomTab
  71.     Inherits TabControl
  72.  
  73.     Sub New()
  74.         DoubleBuffered = True
  75.     End Sub
  76.  
  77.     Protected Overrides Sub OnCreateControl()
  78.         MyBase.OnCreateControl()
  79.         SetStyle(ControlStyles.UserPaint, True)
  80.         Alignment = TabAlignment.Left
  81.         ItemSize = New Point(30, 140)
  82.     End Sub
  83.  
  84.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  85.  
  86.         Dim G As Graphics = e.Graphics
  87.         G.SmoothingMode = SmoothingMode.HighQuality
  88.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
  89.  
  90.         MyBase.OnPaint(e)
  91.  
  92.         G.Clear(Color.FromArgb(244, 244, 244))
  93.  
  94.         G.DrawRectangle(New Pen(Color.FromArgb(170, 170, 170)), New Rectangle(0, 0, Width - 1, Height - 1))
  95.  
  96.         For i As Integer = 0 To TabPages.Count - 1
  97.  
  98.             Try : TabPages(i).BackColor = Color.FromArgb(244, 244, 244) : Catch : End Try
  99.  
  100.             G.FillRectangle(New SolidBrush(Color.FromArgb(244, 244, 244)), GetTabRect(i))
  101.  
  102.             If SelectedIndex = i Then
  103.                 CenterString(G, TabPages(i).Text.ToUpper, New Font("Segoe UI", 9, FontStyle.Bold), New SolidBrush(Color.FromArgb(70, 150, 180)), GetTabRect(i))
  104.             Else
  105.                 CenterString(G, TabPages(i).Text.ToUpper, New Font("Segoe UI", 9, FontStyle.Bold), New SolidBrush(Color.Black), GetTabRect(i))
  106.             End If
  107.  
  108.         Next
  109.  
  110.     End Sub
  111.  
  112. End Class
  113.  
  114. Class BlackPaginator
  115.     Inherits Control
  116.  
  117.     Sub New()
  118.         DoubleBuffered = True
  119.     End Sub
  120.  
  121.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  122.  
  123.         Dim G As Graphics = e.Graphics
  124.         G.SmoothingMode = SmoothingMode.HighQuality
  125.         G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
  126.  
  127.         MyBase.OnPaint(e)
  128.  
  129.         G.FillRectangle(New SolidBrush(Color.FromArgb(48, 48, 48)), New Rectangle(0, 0, Width - 1, Height - 1))
  130.         Helpers.CenterString(G, Text, New Font("Segoe UI", 9), Brushes.White, New Rectangle(0, 0, Width - 1, Height - 1))
  131.  
  132.     End Sub
  133.  
  134. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement