Advertisement
Yamatano

MetroTheme 1.3.2

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