Advertisement
Yamatano

MetroTheme 1.3

Jul 31st, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 25.95 KB | None | 0 0
  1. 'Thanks to Aeonhack and other
  2. 'You need paste here ThemeBase 1.5.4, then delete first two lines
  3. 'VERSION 1.3, 31.07.2015
  4. 'CHANGELOG 1.3: Added TabControl (BETA)
  5. Imports System.Drawing.Drawing2D
  6. Imports System.ComponentModel
  7. Class MetroButton
  8.     Inherits ThemeControl154
  9.     Sub New()
  10.         Height = 45
  11.         Width = 120
  12.         Font = New Font("Segoe UI", 12)
  13.     End Sub
  14.     Dim buttonc As Color
  15.     Dim textc As Brush
  16.     Protected Overrides Sub ColorHook()
  17.         buttonc = GetColor("ButtonColor")
  18.         textc = GetBrush("TextColor")
  19.     End Sub
  20.     Protected Overrides Sub PaintHook()
  21.         G.Clear(buttonc)
  22.         Select Case State
  23.             Case MouseState.None
  24.                 DrawText(textc, HorizontalAlignment.Center, 0, 0)
  25.             Case MouseState.Over
  26.                 G.FillRectangle(New SolidBrush(Color.FromArgb(25, Color.Black)), New Rectangle(0, 0, Width, Height))
  27.                 DrawText(textc, HorizontalAlignment.Center, 0, 0)
  28.             Case MouseState.Down
  29.                 G.FillRectangle(New SolidBrush(Color.FromArgb(50, Color.Black)), New Rectangle(0, 0, Width, Height))
  30.                 DrawText(textc, HorizontalAlignment.Center, 0, 0)
  31.         End Select
  32.     End Sub
  33. End Class
  34. Class MetroForm
  35.     Inherits ThemeContainer154
  36.     Sub New()
  37.         TransparencyKey = Color.Fuchsia
  38.         BackColor = Color.White
  39.         Font = New Font("Segoe UI", 10)
  40.         SetColor("BorderColor", Color.Black)
  41.         SetColor("TextColor", Color.White)
  42.     End Sub
  43.     Dim Borderc As Color
  44.     Dim Textc As Brush
  45.     Protected Overrides Sub ColorHook()
  46.         Borderc = GetColor("BorderColor")
  47.         Textc = GetBrush("TextColor")
  48.     End Sub
  49.     Protected Overrides Sub PaintHook()
  50.         G.Clear(Borderc)
  51.         G.FillRectangle(New SolidBrush(BackColor), New Rectangle(6, 36, Width - 13, Height - 43))
  52.         G.DrawString(FindForm.Text, Font, Textc, New Point(30, 9))
  53.         G.DrawIcon(FindForm.Icon, New Rectangle(6, 10, 16, 16))
  54.         DrawCorners(Color.Fuchsia)
  55.     End Sub
  56. End Class
  57. Class MetroProgressBar
  58.     Inherits ThemeControl154
  59.     Dim backgroundc As Color
  60.     Dim progressc As Brush
  61.     Dim borderc As Pen
  62.     Private _Maximum As Integer = 100
  63.     Public Property Maximum() As Integer
  64.         Get
  65.             Return _Maximum
  66.         End Get
  67.         Set(ByVal v As Integer)
  68.             If v < 0 Then v = 0
  69.             If v < _Value Then _Value = v
  70.             _Maximum = v
  71.             Invalidate()
  72.         End Set
  73.     End Property
  74.     Private _Value As Integer
  75.     Public Property Value() As Integer
  76.         Get
  77.             Return _Value
  78.         End Get
  79.         Set(ByVal v As Integer)
  80.             If v > _Maximum Then v = _Maximum
  81.             _Value = v
  82.             Invalidate()
  83.         End Set
  84.     End Property
  85.     Sub New()
  86.         SetColor("ProgressColor", Color.Black)
  87.         SetColor("BackgroundColor", Color.White)
  88.         SetColor("BorderColor", Color.Black)
  89.     End Sub
  90.     Protected Overrides Sub ColorHook()
  91.         backgroundc = GetColor("BackgroundColor")
  92.         progressc = GetBrush("ProgressColor")
  93.         borderc = GetPen("BorderColor")
  94.     End Sub
  95.     Protected Overrides Sub PaintHook()
  96.         G.Clear(backgroundc)
  97.         G.FillRectangle(progressc, 0, 0, CInt(_Value / _Maximum * Width), Height)
  98.         G.FillRectangle(progressc, New Rectangle(0, 0, CInt(_Value / _Maximum * Width), Height))
  99.         DrawGradient(Color.FromArgb(0, Color.White), Color.FromArgb(0, Color.White), ClientRectangle)
  100.         DrawBorders(borderc, ClientRectangle)
  101.     End Sub
  102. End Class
  103. <DefaultEvent("TextChanged")>
  104. Class MetroTextBox
  105.     Inherits ThemeControl154
  106.     Private _TextAlign As HorizontalAlignment = HorizontalAlignment.Left
  107.     Property TextAlign() As HorizontalAlignment
  108.         Get
  109.             Return _TextAlign
  110.         End Get
  111.         Set(ByVal value As HorizontalAlignment)
  112.             _TextAlign = value
  113.             If Base IsNot Nothing Then
  114.                 Base.TextAlign = value
  115.             End If
  116.         End Set
  117.     End Property
  118.     Private _MaxLength As Integer = 32767
  119.     Property MaxLength() As Integer
  120.         Get
  121.             Return _MaxLength
  122.         End Get
  123.         Set(ByVal value As Integer)
  124.             _MaxLength = value
  125.             If Base IsNot Nothing Then
  126.                 Base.MaxLength = value
  127.             End If
  128.         End Set
  129.     End Property
  130.     Private _ReadOnly As Boolean
  131.     Property [ReadOnly]() As Boolean
  132.         Get
  133.             Return _ReadOnly
  134.         End Get
  135.         Set(ByVal value As Boolean)
  136.             _ReadOnly = value
  137.             If Base IsNot Nothing Then
  138.                 Base.ReadOnly = value
  139.             End If
  140.         End Set
  141.     End Property
  142.     Private _UseSystemPasswordChar As Boolean
  143.     Property UseSystemPasswordChar() As Boolean
  144.         Get
  145.             Return _UseSystemPasswordChar
  146.         End Get
  147.         Set(ByVal value As Boolean)
  148.             _UseSystemPasswordChar = value
  149.             If Base IsNot Nothing Then
  150.                 Base.UseSystemPasswordChar = value
  151.             End If
  152.         End Set
  153.     End Property
  154.     Private _Multiline As Boolean
  155.     Property Multiline() As Boolean
  156.         Get
  157.             Return _Multiline
  158.         End Get
  159.         Set(ByVal value As Boolean)
  160.             _Multiline = value
  161.             If Base IsNot Nothing Then
  162.                 Base.Multiline = value
  163.  
  164.                 If value Then
  165.                     LockHeight = 0
  166.                     Base.Height = Height - 11
  167.                 Else
  168.                     LockHeight = Base.Height + 11
  169.                 End If
  170.             End If
  171.         End Set
  172.     End Property
  173.     Overrides Property Text() As String
  174.         Get
  175.             Return MyBase.Text
  176.         End Get
  177.         Set(ByVal value As String)
  178.             MyBase.Text = value
  179.             If Base IsNot Nothing Then
  180.                 Base.Text = value
  181.             End If
  182.         End Set
  183.     End Property
  184.     Overrides Property Font() As Font
  185.         Get
  186.             Return MyBase.Font
  187.         End Get
  188.         Set(ByVal value As Font)
  189.             MyBase.Font = value
  190.             If Base IsNot Nothing Then
  191.                 Base.Font = value
  192.                 Base.Location = New Point(3, 5)
  193.                 Base.Width = Width - 6
  194.                 If Not _Multiline Then
  195.                     LockHeight = Base.Height + 11
  196.                 End If
  197.             End If
  198.         End Set
  199.     End Property
  200.     Protected Overrides Sub OnCreation()
  201.         If Not Controls.Contains(Base) Then
  202.             Controls.Add(Base)
  203.         End If
  204.     End Sub
  205.     Private Base As TextBox
  206.     Sub New()
  207.         Base = New TextBox
  208.         Base.Font = Font
  209.         Base.Text = Text
  210.         Base.MaxLength = _MaxLength
  211.         Base.Multiline = _Multiline
  212.         Base.ReadOnly = _ReadOnly
  213.         Base.UseSystemPasswordChar = _UseSystemPasswordChar
  214.         Base.BorderStyle = BorderStyle.None
  215.         Base.Location = New Point(4, 4)
  216.         Base.Width = Width - 10
  217.         If _Multiline Then
  218.             Base.Height = Height - 11
  219.         Else
  220.             LockHeight = Base.Height + 11
  221.         End If
  222.         AddHandler Base.TextChanged, AddressOf OnBaseTextChanged
  223.         AddHandler Base.KeyDown, AddressOf OnBaseKeyDown
  224.         SetColor("TextColor", Color.Black)
  225.         SetColor("BackgroundColor", Color.White)
  226.         SetColor("BorderColor", Color.Black)
  227.     End Sub
  228.     Private backgroundc As Color
  229.     Private borderc As Pen
  230.     Private textc As Brush
  231.     Protected Overrides Sub ColorHook()
  232.         backgroundc = GetColor("BackgroundColor")
  233.         borderc = GetPen("BorderColor")
  234.         textc = GetBrush("TextColor")
  235.         Base.BackColor = GetColor("BackgroundColor")
  236.         Base.ForeColor = GetColor("TextColor")
  237.     End Sub
  238.     Protected Overrides Sub PaintHook()
  239.         G.Clear(backgroundc)
  240.         DrawBorders(borderc)
  241.     End Sub
  242.     Private Sub OnBaseTextChanged(ByVal s As Object, ByVal e As EventArgs)
  243.         Text = Base.Text
  244.     End Sub
  245.     Private Sub OnBaseKeyDown(ByVal s As Object, ByVal e As KeyEventArgs)
  246.         If e.Control AndAlso e.KeyCode = Keys.A Then
  247.             Base.SelectAll()
  248.             e.SuppressKeyPress = True
  249.         End If
  250.     End Sub
  251.     Protected Overrides Sub OnResize(ByVal e As EventArgs)
  252.         Base.Location = New Point(4, 5)
  253.         Base.Width = Width - 8
  254.         If _Multiline Then
  255.             Base.Height = Height - 5
  256.         End If
  257.         MyBase.OnResize(e)
  258.     End Sub
  259. End Class
  260. <DefaultEvent("CheckedChanged")>
  261. Class MetroCheckButton
  262.     Inherits ThemeControl154
  263.     Sub New()
  264.         LockHeight = 20
  265.         Width = 120
  266.         SetColor("TextColor", Color.Black)
  267.         SetColor("BackgroundColor", Color.White)
  268.         SetColor("CheckColor", Color.Black)
  269.         SetColor("BorderColor", Color.Black)
  270.         SetColor("CheckBackgroundColor", Color.White)
  271.         Font = New Font("Segoe UI", 12)
  272.     End Sub
  273.     Private X As Integer
  274.     Private textc As Color
  275.     Private backgroundc As Color
  276.     Private checkc As Brush
  277.     Private borderc As Color
  278.     Private checkbackgroundc As Color
  279.     Protected Overrides Sub ColorHook()
  280.         textc = GetColor("TextColor")
  281.         backgroundc = GetColor("BackgroundColor")
  282.         checkc = GetBrush("CheckColor")
  283.         borderc = GetColor("BorderColor")
  284.         checkbackgroundc = GetColor("CheckBackgroundColor")
  285.     End Sub
  286.     Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  287.         MyBase.OnMouseMove(e)
  288.         X = e.Location.X
  289.         Invalidate()
  290.     End Sub
  291.     Protected Overrides Sub PaintHook()
  292.         G.Clear(backgroundc)
  293.         If _Checked Then
  294.             G.FillRectangle(New SolidBrush(borderc), New Rectangle(0, 0, 20, 20))
  295.             G.FillRectangle(New SolidBrush(checkbackgroundc), New Rectangle(1, 1, 20 - 2, 20 - 2))
  296.         Else
  297.             G.FillRectangle(New SolidBrush(borderc), New Rectangle(0, 0, 20, 20))
  298.             G.FillRectangle(New SolidBrush(checkbackgroundc), New Rectangle(1, 1, 20 - 2, 20 - 2))
  299.         End If
  300.         If State = MouseState.Over And X < 15 Then
  301.             G.FillRectangle(New SolidBrush(borderc), New Rectangle(0, 0, 20, 20))
  302.             G.FillRectangle(New SolidBrush(checkbackgroundc), New Rectangle(1, 1, 20 - 2, 20 - 2))
  303.         ElseIf State = MouseState.Down And X < 15 Then
  304.             G.FillRectangle(New SolidBrush(borderc), New Rectangle(0, 0, 20, 20))
  305.             G.FillRectangle(New SolidBrush(checkbackgroundc), New Rectangle(1, 1, 20 - 2, 20 - 2))
  306.         End If
  307.         If _Checked Then G.DrawString("a", New Font("Marlett", 20), checkc, New Point(-7, -5))
  308.         DrawText(New SolidBrush(textc), HorizontalAlignment.Left, 25, 0)
  309.     End Sub
  310.     Private _Checked As Boolean
  311.     Property Checked() As Boolean
  312.         Get
  313.             Return _Checked
  314.         End Get
  315.         Set(ByVal value As Boolean)
  316.             _Checked = value
  317.             Invalidate()
  318.         End Set
  319.     End Property
  320.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  321.         _Checked = Not _Checked
  322.         RaiseEvent CheckedChanged(Me)
  323.         MyBase.OnMouseDown(e)
  324.     End Sub
  325.     Event CheckedChanged(ByVal sender As Object)
  326. End Class
  327. <DefaultEvent("CheckedChanged")>
  328. Class MetroRadioButton
  329.     Inherits ThemeControl154
  330.     Sub New()
  331.         LockHeight = 20
  332.         SetColor("TextColor", Color.Black)
  333.         SetColor("BackgroundColor", Color.White)
  334.         SetColor("CheckColor", Color.Black)
  335.         SetColor("BorderColor", Color.Black)
  336.         Font = New Font("Segoe UI", 12)
  337.         Width = 120
  338.     End Sub
  339.     Private X As Integer
  340.     Private textc As Color
  341.     Private backgroundc As Color
  342.     Private checkc As Color
  343.     Private borderc As Color
  344.     Protected Overrides Sub ColorHook()
  345.         textc = GetColor("TextColor")
  346.         backgroundc = GetColor("BackgroundColor")
  347.         checkc = GetColor("CheckColor")
  348.         borderc = GetColor("BorderColor")
  349.     End Sub
  350.     Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  351.         MyBase.OnMouseMove(e)
  352.         X = e.Location.X
  353.         Invalidate()
  354.     End Sub
  355.     Protected Overrides Sub PaintHook()
  356.         G.Clear(backgroundc)
  357.         G.SmoothingMode = SmoothingMode.HighQuality
  358.         If _Checked Then
  359.             G.DrawEllipse(New Pen(borderc), New Rectangle(New Point(0, 0), New Size(20, 20)))
  360.             G.FillEllipse(New SolidBrush(checkc), New Rectangle(New Point(3, 3), New Size(14, 14)))
  361.         Else
  362.             G.DrawEllipse(New Pen(borderc), New Rectangle(New Point(0, 0), New Size(20, 20)))
  363.             DrawText(New SolidBrush(textc), HorizontalAlignment.Left, 25, 0)
  364.         End If
  365.         If _Checked Then DrawText(New SolidBrush(textc), HorizontalAlignment.Left, 25, 0)
  366.     End Sub
  367.     Private _Field As Integer = 21
  368.     Property Field() As Integer
  369.         Get
  370.             Return _Field
  371.         End Get
  372.         Set(ByVal value As Integer)
  373.             If value < 4 Then Return
  374.             _Field = value
  375.             LockHeight = value
  376.             Invalidate()
  377.         End Set
  378.     End Property
  379.     Private _Checked As Boolean
  380.     Property Checked() As Boolean
  381.         Get
  382.             Return _Checked
  383.         End Get
  384.         Set(ByVal value As Boolean)
  385.             _Checked = value
  386.             InvalidateControls()
  387.             RaiseEvent CheckedChanged(Me)
  388.             Invalidate()
  389.         End Set
  390.     End Property
  391.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  392.         If Not _Checked Then Checked = True
  393.         MyBase.OnMouseDown(e)
  394.     End Sub
  395.     Event CheckedChanged(ByVal sender As Object)
  396.     Protected Overrides Sub OnCreation()
  397.         InvalidateControls()
  398.     End Sub
  399.     Private Sub InvalidateControls()
  400.         If Not IsHandleCreated OrElse Not _Checked Then Return
  401.         For Each C As Control In Parent.Controls
  402.             If C IsNot Me AndAlso TypeOf C Is MetroRadioButton Then
  403.                 DirectCast(C, MetroRadioButton).Checked = False
  404.             End If
  405.         Next
  406.     End Sub
  407. End Class
  408. Class MetroGroupBox
  409.     Inherits ThemeContainer154
  410.     Sub New()
  411.         ControlMode = True
  412.         SetColor("BackgroundColor", Color.Black)
  413.         SetColor("InsideBackgroundColor", Color.White)
  414.         SetColor("TextColor", Color.White)
  415.     End Sub
  416.     Dim backgroundc As Color
  417.     Dim insidebackgroundc As Color
  418.     Dim textc As Brush
  419.     Protected Overrides Sub ColorHook()
  420.         backgroundc = GetColor("BackgroundColor")
  421.         insidebackgroundc = GetColor("InsideBackgroundColor")
  422.         textc = GetBrush("TextColor")
  423.     End Sub
  424.     Protected Overrides Sub PaintHook()
  425.         G.Clear(backgroundc)
  426.         G.FillRectangle(New SolidBrush(insidebackgroundc), New Rectangle(1, 25, Width - 2, Height - 26))
  427.         DrawText(textc, HorizontalAlignment.Left, 2, 0)
  428.     End Sub
  429. End Class
  430. Class MetroControls
  431.     Inherits ThemeControl154
  432.     Private X As Integer
  433.     Dim backgroundc As Color
  434.     Dim edgec As Pen
  435.     Dim iconsc As Color
  436.     Dim glowc As SolidBrush
  437.     Dim a, b, c As Integer
  438.     Protected Overrides Sub ColorHook()
  439.         iconsc = GetColor("IconsColor")
  440.         backgroundc = GetColor("BackgroundColor")
  441.     End Sub
  442.     Sub New()
  443.         IsAnimated = True
  444.         SetColor("IconsColor", Color.White)
  445.         SetColor("BackgroundColor", Color.Transparent)
  446.         Me.Size = New Size(84, 18)
  447.         Me.Anchor = AnchorStyles.Top Or AnchorStyles.Right
  448.     End Sub
  449.     Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  450.         MyBase.OnMouseMove(e)
  451.         X = e.X
  452.         Invalidate()
  453.     End Sub
  454.     Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
  455.         MyBase.OnClick(e)
  456.         If X <= 22 Then
  457.             FindForm.WindowState = FormWindowState.Minimized
  458.         ElseIf X > 22 And X <= 46 Then
  459.             If FindForm.WindowState = FormWindowState.Maximized Then FindForm.WindowState = FormWindowState.Normal Else FindForm.WindowState = FormWindowState.Maximized
  460.         Else
  461.             FindForm.Close()
  462.         End If
  463.     End Sub
  464.     Protected Overrides Sub OnAnimation()
  465.         MyBase.OnAnimation()
  466.         Select Case State
  467.             Case MouseState.Over
  468.                 If a < 24 And X <= 22 Then
  469.                     a += 4
  470.                     If b > 0 Then
  471.                         b -= 4
  472.                     End If
  473.                     If c > 0 Then
  474.                         c -= 4
  475.                     End If
  476.                     If b < 0 Then b = 0
  477.                     If c < 0 Then c = 0
  478.                     Invalidate()
  479.                     Application.DoEvents()
  480.                 End If
  481.                 If b < 24 And X > 22 And X <= 46 Then
  482.                     b += 4
  483.                     If a > 0 Then
  484.                         a -= 4
  485.                     End If
  486.                     If a < 0 Then a = 0
  487.                     If c > 0 Then
  488.                         c -= 4
  489.                     End If
  490.                     If c < 0 Then c = 0
  491.                     Invalidate()
  492.                     Application.DoEvents()
  493.                 End If
  494.                 If c < 32 And X > 46 Then
  495.                     c += 4
  496.                     If a > 0 Then
  497.                         a -= 4
  498.                     End If
  499.                     If b > 0 Then
  500.                         b -= 4
  501.                     End If
  502.                     If a < 0 Then a = 0
  503.                     If b < 0 Then b = 0
  504.                     Invalidate()
  505.                     Application.DoEvents()
  506.                 End If
  507.             Case MouseState.None
  508.                 If a > 0 Then
  509.                     a -= 4
  510.                 End If
  511.                 If b > 0 Then
  512.                     b -= 4
  513.                 End If
  514.                 If c > 0 Then
  515.                     c -= 4
  516.                 End If
  517.                 If a < 0 Then a = 0
  518.                 If b < 0 Then b = 0
  519.                 If c < 0 Then c = 0
  520.                 Invalidate()
  521.                 Application.DoEvents()
  522.         End Select
  523.     End Sub
  524.     Protected Overrides Sub PaintHook()
  525.         G.Clear(backgroundc)
  526.         Dim SB1 As New SolidBrush(Color.FromArgb(a, Color.Black))
  527.         Dim SB1_ As New SolidBrush(Color.FromArgb(b, Color.Black))
  528.         Dim SB2 As New SolidBrush(Color.FromArgb(c, Color.Black))
  529.         Dim SB3 As New SolidBrush(Color.FromArgb(20, Color.Black))
  530.         Select Case State
  531.             Case MouseState.Down
  532.                 If X <= 22 Then
  533.                     a = 0
  534.                     G.FillRectangle(SB3, New Rectangle(0, 0, 21, 17))
  535.                 ElseIf X > 22 And X <= 46 Then
  536.                     b = 0
  537.                     G.FillRectangle(SB3, New Rectangle(23, 0, 22, 17))
  538.                 Else
  539.                     c = 0
  540.                     G.FillRectangle(SB3, New Rectangle(47, 0, 36, 17))
  541.                 End If
  542.             Case Else
  543.                 If X <= 22 Then
  544.                     G.FillRectangle(SB1, New Rectangle(0, 0, 21, 17))
  545.                 ElseIf X > 22 And X <= 46 Then
  546.                     G.FillRectangle(SB1_, New Rectangle(23, 0, 22, 17))
  547.                 Else
  548.                     G.FillRectangle(SB2, New Rectangle(47, 0, 36, 17))
  549.                 End If
  550.         End Select
  551.         G.DrawString("0", New Font("Marlett", 8.25), GetBrush("IconsColor"), New Point(5, 4))
  552.         If FindForm.WindowState <> FormWindowState.Maximized Then G.DrawString("1", New Font("Marlett", 8), GetBrush("IconsColor"), New Point(28, 4)) Else G.DrawString("2", New Font("Marlett", 8.25), GetBrush("IconsColor"), New Point(28, 4))
  553.         G.DrawString("r", New Font("Marlett", 10), GetBrush("IconsColor"), New Point(56, 3))
  554.     End Sub
  555. End Class
  556. Class MetroLabel
  557.     Inherits Label
  558.     Sub New()
  559.         Font = New Font("Segoe UI", 12)
  560.         ForeColor = Color.Black
  561.         BackColor = Color.Transparent
  562.     End Sub
  563. End Class
  564. Class MetroAlertBox
  565.     Inherits Control
  566.     Private exitLocation As Point
  567.     Private overExit As Boolean
  568.     Enum Style
  569.         _Error
  570.         _Success
  571.         _Warning
  572.         _Notice
  573.     End Enum
  574.     Private _alertStyle As Style
  575.     Public Property AlertStyle As Style
  576.         Get
  577.             Return _alertStyle
  578.         End Get
  579.         Set(ByVal value As Style)
  580.             _alertStyle = value
  581.             Invalidate()
  582.         End Set
  583.     End Property
  584.     Sub New()
  585.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or
  586.                  ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  587.         Font = New Font("Segoe UI", 12)
  588.         Size = New Size(200, 40)
  589.     End Sub
  590.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  591.         MyBase.OnPaint(e)
  592.         Dim G As Graphics = e.Graphics
  593.         G.SmoothingMode = SmoothingMode.HighQuality
  594.         G.Clear(Parent.BackColor)
  595.         Dim borderc As Color
  596.         Dim backgroundc As Color
  597.         Dim textc As Color
  598.         Select Case _alertStyle
  599.             Case Style._Error
  600.                 borderc = Color.Black
  601.                 backgroundc = Color.FromArgb(254, 142, 142)
  602.                 backgroundc = Me.BackColor
  603.                 Me.BackColor = Me.BackColor
  604.                 textc = Color.Black
  605.             Case Style._Notice
  606.                 borderc = Color.Black
  607.                 backgroundc = Color.FromArgb(142, 142, 254)
  608.                 backgroundc = Me.BackColor
  609.                 Me.BackColor = Me.BackColor
  610.                 textc = Color.Black
  611.             Case Style._Success
  612.                 borderc = Color.Black
  613.                 backgroundc = Color.FromArgb(0, 199, 0)
  614.                 backgroundc = Me.BackColor
  615.                 Me.BackColor = Me.BackColor
  616.                 textc = Color.Black
  617.             Case Style._Warning
  618.                 borderc = Color.Black
  619.                 backgroundc = Color.FromArgb(254, 254, 142)
  620.                 backgroundc = Me.BackColor
  621.                 Me.BackColor = Me.BackColor
  622.                 textc = Color.Black
  623.         End Select
  624.         Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  625.         G.FillRectangle(New SolidBrush(backgroundc), mainRect)
  626.         G.DrawRectangle(New Pen(borderc), mainRect)
  627.         Dim styleText As String = Nothing
  628.         Select Case _alertStyle
  629.             Case Style._Error
  630.                 styleText = "Error!"
  631.             Case Style._Notice
  632.                 styleText = "Notice!"
  633.             Case Style._Success
  634.                 styleText = "Success!"
  635.             Case Style._Warning
  636.                 styleText = "Warning!"
  637.         End Select
  638.         Dim styleFont As New Font(Font.FontFamily, Font.Size, FontStyle.Bold)
  639.         Dim textY As Integer = ((Me.Height - 1) / 2) - (G.MeasureString(Text, Font).Height / 2)
  640.         G.DrawString(styleText, styleFont, New SolidBrush(textc), New Point(10, textY))
  641.         G.DrawString(Text, Font, New SolidBrush(textc), New Point(10 + G.MeasureString(styleText, styleFont).Width + 4, textY))
  642.         Dim exitFont As New Font("Marlett", 6)
  643.         Dim exitY As Integer = ((Me.Height - 1) / 2) - (G.MeasureString("r", exitFont).Height / 2) + 1
  644.         exitLocation = New Point(Width - 26, exitY - 3)
  645.         G.DrawString("r", exitFont, New SolidBrush(textc), New Point(Width - 23, exitY))
  646.     End Sub
  647.     Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  648.         MyBase.OnMouseMove(e)
  649.         If e.X >= Width - 26 AndAlso e.X <= Width - 12 AndAlso e.Y > exitLocation.Y AndAlso e.Y < exitLocation.Y + 12 Then
  650.             If Cursor <> Cursors.Hand Then Cursor = Cursors.Hand
  651.             overExit = True
  652.         Else
  653.             If Cursor <> Cursors.Arrow Then Cursor = Cursors.Arrow
  654.             overExit = False
  655.         End If
  656.         Invalidate()
  657.     End Sub
  658.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  659.         MyBase.OnMouseDown(e)
  660.         If overExit Then Me.Visible = False
  661.     End Sub
  662. End Class
  663. Class MetroTabControl
  664.     Inherits TabControl
  665.     Sub New()
  666.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw Or
  667.                  ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
  668.         ItemSize = New Size(0, 30)
  669.         Font = New Font("Segoe UI", 8)
  670.     End Sub
  671.     Protected Overrides Sub CreateHandle()
  672.         MyBase.CreateHandle()
  673.         Alignment = TabAlignment.Top
  674.     End Sub
  675.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  676.         Dim G As Graphics = e.Graphics
  677.         Dim borderc As New Pen(Color.FromArgb(225, 225, 225))
  678.         G.SmoothingMode = SmoothingMode.HighQuality
  679.         G.Clear(Parent.BackColor)
  680.         Dim fillRect As New Rectangle(2, ItemSize.Height + 2, Width - 6, Height - ItemSize.Height - 3)
  681.         G.FillRectangle(Brushes.White, fillRect)
  682.         G.DrawRectangle(borderc, fillRect)
  683.         Dim fontc As New Color
  684.         For i = 0 To TabCount - 1
  685.             Dim mainRect As Rectangle = GetTabRect(i)
  686.             If i = SelectedIndex Then
  687.                 G.FillRectangle(New SolidBrush(Color.White), mainRect)
  688.                 G.DrawRectangle(borderc, mainRect)
  689.                 G.DrawLine(New Pen(Color.Black), New Point(mainRect.X + 1, mainRect.Y), New Point(mainRect.X + mainRect.Width - 1, mainRect.Y))
  690.                 G.DrawLine(Pens.White, New Point(mainRect.X + 1, mainRect.Y + mainRect.Height), New Point(mainRect.X + mainRect.Width - 1, mainRect.Y + mainRect.Height))
  691.                 fontc = Color.Black
  692.             Else
  693.                 G.FillRectangle(New SolidBrush(Color.FromArgb(143, 143, 143)), mainRect)
  694.                 G.DrawRectangle(borderc, mainRect)
  695.                 fontc = Color.Black
  696.             End If
  697.             Dim titleX As Integer = (mainRect.Location.X + mainRect.Width / 2) - (G.MeasureString(TabPages(i).Text, Font).Width / 2)
  698.             Dim titleY As Integer = (mainRect.Location.Y + mainRect.Height / 2) - (G.MeasureString(TabPages(i).Text, Font).Height / 2)
  699.             G.DrawString(TabPages(i).Text, Font, New SolidBrush(fontc), New Point(titleX, titleY))
  700.             Try : TabPages(i).BackColor = Color.White : Catch : End Try
  701.         Next
  702.     End Sub
  703. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement