Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Region " Imports "
  2.  
  3. Imports System.Drawing.Drawing2D
  4. Imports System.ComponentModel
  5.  
  6. #End Region
  7.  
  8. '|------DO-NOT-REMOVE------|
  9. '
  10. ' Creator: HazelDev
  11. ' Site   : HazelDev.com
  12. ' Created: 12.Sep.2014
  13. ' Changed: 26.Sep.2014
  14. ' Version: 1.0.0
  15. '
  16. '|------DO-NOT-REMOVE------|
  17.  
  18. Namespace MonoFlat
  19.  
  20. #Region " RoundRectangle "
  21.  
  22.     Module RoundRectangle
  23.         Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
  24.             Dim P As GraphicsPath = New GraphicsPath()
  25.             Dim ArcRectangleWidth As Integer = Curve * 2
  26.             P.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  27.             P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  28.             P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  29.             P.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  30.             P.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
  31.             Return P
  32.         End Function
  33.     End Module
  34.  
  35. #End Region
  36.  
  37. #Region " ThemeContainer "
  38.  
  39.     Class MonoFlat_ThemeContainer
  40.         Inherits ContainerControl
  41.  
  42. #Region " Enums "
  43.  
  44.         Enum MouseState As Byte
  45.             None = 0
  46.             Over = 1
  47.             Down = 2
  48.             Block = 3
  49.         End Enum
  50.  
  51. #End Region
  52. #Region " Variables "
  53.  
  54.         Private HeaderRect As Rectangle
  55.         Protected State As MouseState
  56.         Private MoveHeight As Integer
  57.         Private MouseP As Point = New Point(0, 0)
  58.         Private Cap As Boolean = False
  59.         Private HasShown As Boolean
  60.  
  61. #End Region
  62. #Region " Properties "
  63.  
  64.         Private _Sizable As Boolean = True
  65.         Property Sizable() As Boolean
  66.             Get
  67.                 Return _Sizable
  68.             End Get
  69.             Set(ByVal value As Boolean)
  70.                 _Sizable = value
  71.             End Set
  72.         End Property
  73.  
  74.         Private _SmartBounds As Boolean = True
  75.         Property SmartBounds() As Boolean
  76.             Get
  77.                 Return _SmartBounds
  78.             End Get
  79.             Set(ByVal value As Boolean)
  80.                 _SmartBounds = value
  81.             End Set
  82.         End Property
  83.  
  84.         Private _RoundCorners As Boolean = True
  85.         Property RoundCorners() As Boolean
  86.             Get
  87.                 Return _RoundCorners
  88.             End Get
  89.             Set(ByVal value As Boolean)
  90.                 _RoundCorners = value
  91.                 Invalidate()
  92.             End Set
  93.         End Property
  94.  
  95.         Private _IsParentForm As Boolean
  96.         Protected ReadOnly Property IsParentForm As Boolean
  97.             Get
  98.                 Return _IsParentForm
  99.             End Get
  100.         End Property
  101.  
  102.         Protected ReadOnly Property IsParentMdi As Boolean
  103.             Get
  104.                 If Parent Is Nothing Then Return False
  105.                 Return Parent.Parent IsNot Nothing
  106.             End Get
  107.         End Property
  108.  
  109.         Private _ControlMode As Boolean
  110.         Protected Property ControlMode() As Boolean
  111.             Get
  112.                 Return _ControlMode
  113.             End Get
  114.             Set(ByVal v As Boolean)
  115.                 _ControlMode = v
  116.                 Invalidate()
  117.             End Set
  118.         End Property
  119.  
  120.         Private _StartPosition As FormStartPosition
  121.         Property StartPosition As FormStartPosition
  122.             Get
  123.                 If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.StartPosition Else Return _StartPosition
  124.             End Get
  125.             Set(ByVal value As FormStartPosition)
  126.                 _StartPosition = value
  127.  
  128.                 If _IsParentForm AndAlso Not _ControlMode Then
  129.                     ParentForm.StartPosition = value
  130.                 End If
  131.             End Set
  132.         End Property
  133.  
  134. #End Region
  135. #Region " EventArgs "
  136.  
  137.         Protected NotOverridable Overrides Sub OnParentChanged(ByVal e As EventArgs)
  138.             MyBase.OnParentChanged(e)
  139.  
  140.             If Parent Is Nothing Then Return
  141.             _IsParentForm = TypeOf Parent Is Form
  142.  
  143.             If Not _ControlMode Then
  144.                 InitializeMessages()
  145.  
  146.                 If _IsParentForm Then
  147.                     Me.ParentForm.FormBorderStyle = FormBorderStyle.None
  148.                     Me.ParentForm.TransparencyKey = Color.Fuchsia
  149.  
  150.                     If Not DesignMode Then
  151.                         AddHandler ParentForm.Shown, AddressOf FormShown
  152.                     End If
  153.                 End If
  154.                 Parent.BackColor = BackColor
  155.                 '   Parent.MinimumSize = New Size(261, 65)
  156.            End If
  157.         End Sub
  158.  
  159.         Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  160.             MyBase.OnSizeChanged(e)
  161.             If Not _ControlMode Then HeaderRect = New Rectangle(0, 0, Width - 14, MoveHeight - 7)
  162.             Invalidate()
  163.         End Sub
  164.  
  165.         Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  166.             MyBase.OnMouseDown(e)
  167.             Focus()
  168.             If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  169.             If Not (_IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized OrElse _ControlMode) Then
  170.                 If HeaderRect.Contains(e.Location) Then
  171.                     Capture = False
  172.                     WM_LMBUTTONDOWN = True
  173.                     DefWndProc(Messages(0))
  174.                 ElseIf _Sizable AndAlso Not Previous = 0 Then
  175.                     Capture = False
  176.                     WM_LMBUTTONDOWN = True
  177.                     DefWndProc(Messages(Previous))
  178.                 End If
  179.             End If
  180.         End Sub
  181.  
  182.         Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  183.             MyBase.OnMouseUp(e)
  184.             Cap = False
  185.         End Sub
  186.  
  187.         Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  188.             MyBase.OnMouseMove(e)
  189.             If Not (_IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized) Then
  190.                 If _Sizable AndAlso Not _ControlMode Then InvalidateMouse()
  191.             End If
  192.             If Cap Then
  193.                 Parent.Location = MousePosition - MouseP
  194.             End If
  195.         End Sub
  196.  
  197.         Protected Overrides Sub OnInvalidated(ByVal e As System.Windows.Forms.InvalidateEventArgs)
  198.             MyBase.OnInvalidated(e)
  199.             ParentForm.Text = Text
  200.         End Sub
  201.  
  202.         Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
  203.             MyBase.OnPaintBackground(e)
  204.         End Sub
  205.  
  206.         Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
  207.             MyBase.OnTextChanged(e)
  208.             Invalidate()
  209.         End Sub
  210.  
  211.         Private Sub FormShown(ByVal sender As Object, ByVal e As EventArgs)
  212.             If _ControlMode OrElse HasShown Then Return
  213.  
  214.             If _StartPosition = FormStartPosition.CenterParent OrElse _StartPosition = FormStartPosition.CenterScreen Then
  215.                 Dim SB As Rectangle = Screen.PrimaryScreen.Bounds
  216.                 Dim CB As Rectangle = ParentForm.Bounds
  217.                 ParentForm.Location = New Point(SB.Width \ 2 - CB.Width \ 2, SB.Height \ 2 - CB.Width \ 2)
  218.             End If
  219.             HasShown = True
  220.         End Sub
  221.  
  222. #End Region
  223. #Region " Mouse & Size "
  224.  
  225.         Private Sub SetState(ByVal current As MouseState)
  226.             State = current
  227.             Invalidate()
  228.         End Sub
  229.  
  230.         Private GetIndexPoint As Point
  231.         Private B1x, B2x, B3, B4 As Boolean
  232.         Private Function GetIndex() As Integer
  233.             GetIndexPoint = PointToClient(MousePosition)
  234.             B1x = GetIndexPoint.X < 7
  235.             B2x = GetIndexPoint.X > Width - 7
  236.             B3 = GetIndexPoint.Y < 7
  237.             B4 = GetIndexPoint.Y > Height - 7
  238.  
  239.             If B1x AndAlso B3 Then Return 4
  240.             If B1x AndAlso B4 Then Return 7
  241.             If B2x AndAlso B3 Then Return 5
  242.             If B2x AndAlso B4 Then Return 8
  243.             If B1x Then Return 1
  244.             If B2x Then Return 2
  245.             If B3 Then Return 3
  246.             If B4 Then Return 6
  247.             Return 0
  248.         End Function
  249.  
  250.         Private Current, Previous As Integer
  251.         Private Sub InvalidateMouse()
  252.             Current = GetIndex()
  253.             If Current = Previous Then Return
  254.  
  255.             Previous = Current
  256.             Select Case Previous
  257.                 Case 0
  258.                     Cursor = Cursors.Default
  259.                 Case 6
  260.                     Cursor = Cursors.SizeNS
  261.                 Case 8
  262.                     Cursor = Cursors.SizeNWSE
  263.                 Case 7
  264.                     Cursor = Cursors.SizeNESW
  265.             End Select
  266.         End Sub
  267.  
  268.         Private Messages(8) As Message
  269.         Private Sub InitializeMessages()
  270.             Messages(0) = Message.Create(Parent.Handle, 161, New IntPtr(2), IntPtr.Zero)
  271.             For I As Integer = 1 To 8
  272.                 Messages(I) = Message.Create(Parent.Handle, 161, New IntPtr(I + 9), IntPtr.Zero)
  273.             Next
  274.         End Sub
  275.  
  276.         Private Sub CorrectBounds(ByVal bounds As Rectangle)
  277.             If Parent.Width > bounds.Width Then Parent.Width = bounds.Width
  278.             If Parent.Height > bounds.Height Then Parent.Height = bounds.Height
  279.  
  280.             Dim X As Integer = Parent.Location.X
  281.             Dim Y As Integer = Parent.Location.Y
  282.  
  283.             If X < bounds.X Then X = bounds.X
  284.             If Y < bounds.Y Then Y = bounds.Y
  285.  
  286.             Dim Width As Integer = bounds.X + bounds.Width
  287.             Dim Height As Integer = bounds.Y + bounds.Height
  288.  
  289.             If X + Parent.Width > Width Then X = Width - Parent.Width
  290.             If Y + Parent.Height > Height Then Y = Height - Parent.Height
  291.  
  292.             Parent.Location = New Point(X, Y)
  293.         End Sub
  294.  
  295.         Private WM_LMBUTTONDOWN As Boolean
  296.         Protected Overrides Sub WndProc(ByRef m As Message)
  297.             MyBase.WndProc(m)
  298.  
  299.             If WM_LMBUTTONDOWN AndAlso m.Msg = 513 Then
  300.                 WM_LMBUTTONDOWN = False
  301.  
  302.                 SetState(MouseState.Over)
  303.                 If Not _SmartBounds Then Return
  304.  
  305.                 If IsParentMdi Then
  306.                     CorrectBounds(New Rectangle(Point.Empty, Parent.Parent.Size))
  307.                 Else
  308.                     CorrectBounds(Screen.FromControl(Parent).WorkingArea)
  309.                 End If
  310.             End If
  311.         End Sub
  312.  
  313. #End Region
  314.  
  315.         Protected Overrides Sub CreateHandle()
  316.             MyBase.CreateHandle()
  317.         End Sub
  318.  
  319.         Sub New()
  320.             SetStyle(DirectCast(139270, ControlStyles), True)
  321.             BackColor = Color.FromArgb(32, 41, 50)
  322.             Padding = New Padding(10, 70, 10, 9)
  323.             DoubleBuffered = True
  324.             Dock = DockStyle.Fill
  325.             MoveHeight = 66
  326.             Font = New Font("Segoe UI", 9)
  327.         End Sub
  328.  
  329.         Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  330.             MyBase.OnPaint(e)
  331.             Dim G As Graphics = e.Graphics
  332.  
  333.             G.Clear(Color.FromArgb(32, 41, 50))
  334.             G.FillRectangle(New SolidBrush(Color.FromArgb(181, 41, 42)), New Rectangle(0, 0, Width, 60))
  335.  
  336.             If _RoundCorners = True Then
  337.                 ' Draw Left upper corner
  338.                G.FillRectangle(Brushes.Fuchsia, 0, 0, 1, 1)
  339.                 G.FillRectangle(Brushes.Fuchsia, 1, 0, 1, 1)
  340.                 G.FillRectangle(Brushes.Fuchsia, 2, 0, 1, 1)
  341.                 G.FillRectangle(Brushes.Fuchsia, 3, 0, 1, 1)
  342.                 G.FillRectangle(Brushes.Fuchsia, 0, 1, 1, 1)
  343.                 G.FillRectangle(Brushes.Fuchsia, 0, 2, 1, 1)
  344.                 G.FillRectangle(Brushes.Fuchsia, 0, 3, 1, 1)
  345.                 G.FillRectangle(Brushes.Fuchsia, 1, 1, 1, 1)
  346.  
  347.                 G.FillRectangle(New SolidBrush(Color.FromArgb(181, 41, 42)), 1, 3, 1, 1)
  348.                 G.FillRectangle(New SolidBrush(Color.FromArgb(181, 41, 42)), 1, 2, 1, 1)
  349.                 G.FillRectangle(New SolidBrush(Color.FromArgb(181, 41, 42)), 2, 1, 1, 1)
  350.                 G.FillRectangle(New SolidBrush(Color.FromArgb(181, 41, 42)), 3, 1, 1, 1)
  351.  
  352.                 ' Draw right upper corner
  353.                G.FillRectangle(Brushes.Fuchsia, Width - 1, 0, 1, 1)
  354.                 G.FillRectangle(Brushes.Fuchsia, Width - 2, 0, 1, 1)
  355.                 G.FillRectangle(Brushes.Fuchsia, Width - 3, 0, 1, 1)
  356.                 G.FillRectangle(Brushes.Fuchsia, Width - 4, 0, 1, 1)
  357.                 G.FillRectangle(Brushes.Fuchsia, Width - 1, 1, 1, 1)
  358.                 G.FillRectangle(Brushes.Fuchsia, Width - 1, 2, 1, 1)
  359.                 G.FillRectangle(Brushes.Fuchsia, Width - 1, 3, 1, 1)
  360.                 G.FillRectangle(Brushes.Fuchsia, Width - 2, 1, 1, 1)
  361.  
  362.                 G.FillRectangle(New SolidBrush(Color.FromArgb(181, 41, 42)), Width - 2, 3, 1, 1)
  363.                 G.FillRectangle(New SolidBrush(Color.FromArgb(181, 41, 42)), Width - 2, 2, 1, 1)
  364.                 G.FillRectangle(New SolidBrush(Color.FromArgb(181, 41, 42)), Width - 3, 1, 1, 1)
  365.                 G.FillRectangle(New SolidBrush(Color.FromArgb(181, 41, 42)), Width - 4, 1, 1, 1)
  366.  
  367.                 ' Draw Left bottom corner
  368.                G.FillRectangle(Brushes.Fuchsia, 0, Height - 1, 1, 1)
  369.                 G.FillRectangle(Brushes.Fuchsia, 0, Height - 2, 1, 1)
  370.                 G.FillRectangle(Brushes.Fuchsia, 0, Height - 3, 1, 1)
  371.                 G.FillRectangle(Brushes.Fuchsia, 0, Height - 4, 1, 1)
  372.                 G.FillRectangle(Brushes.Fuchsia, 1, Height - 1, 1, 1)
  373.                 G.FillRectangle(Brushes.Fuchsia, 2, Height - 1, 1, 1)
  374.                 G.FillRectangle(Brushes.Fuchsia, 3, Height - 1, 1, 1)
  375.                 G.FillRectangle(Brushes.Fuchsia, 1, Height - 1, 1, 1)
  376.                 G.FillRectangle(Brushes.Fuchsia, 1, Height - 2, 1, 1)
  377.  
  378.                 G.FillRectangle(New SolidBrush(Color.FromArgb(32, 41, 50)), 1, Height - 3, 1, 1)
  379.                 G.FillRectangle(New SolidBrush(Color.FromArgb(32, 41, 50)), 1, Height - 4, 1, 1)
  380.                 G.FillRectangle(New SolidBrush(Color.FromArgb(32, 41, 50)), 3, Height - 2, 1, 1)
  381.                 G.FillRectangle(New SolidBrush(Color.FromArgb(32, 41, 50)), 2, Height - 2, 1, 1)
  382.  
  383.                 ' Draw right bottom corner
  384.                G.FillRectangle(Brushes.Fuchsia, Width - 1, Height, 1, 1)
  385.                 G.FillRectangle(Brushes.Fuchsia, Width - 2, Height, 1, 1)
  386.                 G.FillRectangle(Brushes.Fuchsia, Width - 3, Height, 1, 1)
  387.                 G.FillRectangle(Brushes.Fuchsia, Width - 4, Height, 1, 1)
  388.                 G.FillRectangle(Brushes.Fuchsia, Width - 1, Height - 1, 1, 1)
  389.                 G.FillRectangle(Brushes.Fuchsia, Width - 1, Height - 2, 1, 1)
  390.                 G.FillRectangle(Brushes.Fuchsia, Width - 1, Height - 3, 1, 1)
  391.                 G.FillRectangle(Brushes.Fuchsia, Width - 2, Height - 1, 1, 1)
  392.                 G.FillRectangle(Brushes.Fuchsia, Width - 3, Height - 1, 1, 1)
  393.                 G.FillRectangle(Brushes.Fuchsia, Width - 4, Height - 1, 1, 1)
  394.                 G.FillRectangle(Brushes.Fuchsia, Width - 1, Height - 4, 1, 1)
  395.                 G.FillRectangle(Brushes.Fuchsia, Width - 2, Height - 2, 1, 1)
  396.  
  397.                 G.FillRectangle(New SolidBrush(Color.FromArgb(32, 41, 50)), Width - 2, Height - 3, 1, 1)
  398.                 G.FillRectangle(New SolidBrush(Color.FromArgb(32, 41, 50)), Width - 2, Height - 4, 1, 1)
  399.                 G.FillRectangle(New SolidBrush(Color.FromArgb(32, 41, 50)), Width - 4, Height - 2, 1, 1)
  400.                 G.FillRectangle(New SolidBrush(Color.FromArgb(32, 41, 50)), Width - 3, Height - 2, 1, 1)
  401.             End If
  402.  
  403.             G.DrawString(Text, New Font("Microsoft Sans Serif", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(255, 254, 255)), New Rectangle(20, 20, Width - 1, Height), New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near})
  404.         End Sub
  405.     End Class
  406.  
  407. #End Region
  408. #Region " ControlBox "
  409.  
  410.     Class MonoFlat_ControlBox
  411.         Inherits Control
  412.  
  413. #Region " Enums "
  414.  
  415.         Enum ButtonHoverState
  416.             Minimize
  417.             Maximize
  418.             Close
  419.             None
  420.         End Enum
  421.  
  422. #End Region
  423. #Region " Variables "
  424.  
  425.         Private ButtonHState As ButtonHoverState = ButtonHoverState.None
  426.  
  427. #End Region
  428. #Region " Properties "
  429.  
  430.         Private _EnableMaximize As Boolean = True
  431.         Property EnableMaximizeButton() As Boolean
  432.             Get
  433.                 Return _EnableMaximize
  434.             End Get
  435.             Set(ByVal value As Boolean)
  436.                 _EnableMaximize = value
  437.                 Invalidate()
  438.             End Set
  439.         End Property
  440.  
  441.         Private _EnableMinimize As Boolean = True
  442.         Property EnableMinimizeButton() As Boolean
  443.             Get
  444.                 Return _EnableMinimize
  445.             End Get
  446.             Set(ByVal value As Boolean)
  447.                 _EnableMinimize = value
  448.                 Invalidate()
  449.             End Set
  450.         End Property
  451.  
  452.         Private _EnableHoverHighlight As Boolean = False
  453.         Property EnableHoverHighlight() As Boolean
  454.             Get
  455.                 Return _EnableHoverHighlight
  456.             End Get
  457.             Set(ByVal value As Boolean)
  458.                 _EnableHoverHighlight = value
  459.                 Invalidate()
  460.             End Set
  461.         End Property
  462.  
  463. #End Region
  464. #Region " EventArgs "
  465.  
  466.         Protected Overrides Sub OnResize(ByVal e As EventArgs)
  467.             MyBase.OnResize(e)
  468.             Size = New Size(100, 25)
  469.         End Sub
  470.  
  471.         Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  472.             MyBase.OnMouseMove(e)
  473.             Dim X As Integer = e.Location.X
  474.             Dim Y As Integer = e.Location.Y
  475.             If Y > 0 AndAlso Y < (Height - 2) Then
  476.                 If X > 0 AndAlso X < 34 Then
  477.                     ButtonHState = ButtonHoverState.Minimize
  478.                 ElseIf X > 33 AndAlso X < 65 Then
  479.                     ButtonHState = ButtonHoverState.Maximize
  480.                 ElseIf X > 64 AndAlso X < Width Then
  481.                     ButtonHState = ButtonHoverState.Close
  482.                 Else
  483.                     ButtonHState = ButtonHoverState.None
  484.                 End If
  485.             Else
  486.                 ButtonHState = ButtonHoverState.None
  487.             End If
  488.             Invalidate()
  489.         End Sub
  490.  
  491.         Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  492.             MyBase.OnMouseDown(e)
  493.             Select Case ButtonHState
  494.                 Case ButtonHoverState.Close
  495.                     Parent.FindForm().Close()
  496.                 Case ButtonHoverState.Minimize
  497.                     If _EnableMinimize = True Then
  498.                         Parent.FindForm().WindowState = FormWindowState.Minimized
  499.                     End If
  500.                 Case ButtonHoverState.Maximize
  501.                     If _EnableMaximize = True Then
  502.                         If Parent.FindForm().WindowState = FormWindowState.Normal Then
  503.                             Parent.FindForm().WindowState = FormWindowState.Maximized
  504.                         Else
  505.                             Parent.FindForm().WindowState = FormWindowState.Normal
  506.                         End If
  507.                     End If
  508.             End Select
  509.         End Sub
  510.         Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  511.             MyBase.OnMouseLeave(e)
  512.             ButtonHState = ButtonHoverState.None : Invalidate()
  513.         End Sub
  514.  
  515.         Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  516.             MyBase.OnMouseDown(e)
  517.             Focus()
  518.         End Sub
  519.  
  520. #End Region
  521.  
  522.         Sub New()
  523.             MyBase.New()
  524.             DoubleBuffered = True
  525.             Anchor = AnchorStyles.Top Or AnchorStyles.Right
  526.         End Sub
  527.  
  528.         Protected Overrides Sub OnCreateControl()
  529.             MyBase.OnCreateControl()
  530.             Try
  531.                 Location = New Point(Parent.Width - 112, 15)
  532.             Catch ex As Exception
  533.             End Try
  534.         End Sub
  535.  
  536.         Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  537.             MyBase.OnPaint(e)
  538.             Dim G As Graphics = e.Graphics
  539.             G.Clear(Color.FromArgb(181, 41, 42))
  540.  
  541.             If _EnableHoverHighlight = True Then
  542.                 Select Case ButtonHState
  543.                     Case ButtonHoverState.None
  544.                         G.Clear(Color.FromArgb(181, 41, 42))
  545.                     Case ButtonHoverState.Minimize
  546.                         If _EnableMinimize = True Then
  547.                             G.FillRectangle(New SolidBrush(Color.FromArgb(156, 35, 35)), New Rectangle(3, 0, 30, Height))
  548.                         End If
  549.                     Case ButtonHoverState.Maximize
  550.                         If _EnableMaximize = True Then
  551.                             G.FillRectangle(New SolidBrush(Color.FromArgb(156, 35, 35)), New Rectangle(35, 0, 30, Height))
  552.                         End If
  553.                     Case ButtonHoverState.Close
  554.                         G.FillRectangle(New SolidBrush(Color.FromArgb(156, 35, 35)), New Rectangle(66, 0, 35, Height))
  555.                 End Select
  556.             End If
  557.  
  558.             'Close
  559.            G.DrawString("r", New Font("Marlett", 12), New SolidBrush(Color.FromArgb(255, 254, 255)), New Point(Width - 16, 8), New StringFormat With {.Alignment = StringAlignment.Center})
  560.  
  561.             'Maximize
  562.            Select Case Parent.FindForm().WindowState
  563.                 Case FormWindowState.Maximized
  564.                     If _EnableMaximize = True Then
  565.                         G.DrawString("2", New Font("Marlett", 12), New SolidBrush(Color.FromArgb(255, 254, 255)), New Point(51, 7), New StringFormat With {.Alignment = StringAlignment.Center})
  566.                     Else
  567.                         G.DrawString("2", New Font("Marlett", 12), New SolidBrush(Color.LightGray), New Point(51, 7), New StringFormat With {.Alignment = StringAlignment.Center})
  568.                     End If
  569.                 Case FormWindowState.Normal
  570.                     If _EnableMaximize = True Then
  571.                         G.DrawString("1", New Font("Marlett", 12), New SolidBrush(Color.FromArgb(255, 254, 255)), New Point(51, 7), New StringFormat With {.Alignment = StringAlignment.Center})
  572.                     Else
  573.                         G.DrawString("1", New Font("Marlett", 12), New SolidBrush(Color.LightGray), New Point(51, 7), New StringFormat With {.Alignment = StringAlignment.Center})
  574.                     End If
  575.             End Select
  576.  
  577.             'Minimize
  578.            If _EnableMinimize = True Then
  579.                 G.DrawString("0", New Font("Marlett", 12), New SolidBrush(Color.FromArgb(255, 254, 255)), New Point(20, 7), New StringFormat With {.Alignment = StringAlignment.Center})
  580.             Else
  581.                 G.DrawString("0", New Font("Marlett", 12), New SolidBrush(Color.LightGray), New Point(20, 7), New StringFormat With {.Alignment = StringAlignment.Center})
  582.             End If
  583.         End Sub
  584.     End Class
  585.  
  586. #End Region
  587. #Region " Button "
  588.  
  589.     Class MonoFlat_Button
  590.         Inherits Control
  591.  
  592. #Region " Variables "
  593.  
  594.         Private MouseState As Integer
  595.         Private Shape As GraphicsPath
  596.         Private InactiveGB, PressedGB As LinearGradientBrush
  597.         Private R1 As Rectangle
  598.         Private P1, P3 As Pen
  599.         Private _Image As Image
  600.         Private _ImageSize As Size
  601.         Private _TextAlignment As StringAlignment = StringAlignment.Center
  602.         Private _TextColor As Color = Color.FromArgb(150, 150, 150)
  603.         Private _ImageAlign As ContentAlignment = ContentAlignment.MiddleLeft
  604.  
  605. #End Region
  606. #Region " Image Designer "
  607.  
  608.         Private Shared Function ImageLocation(ByVal SF As StringFormat, ByVal Area As SizeF, ByVal ImageArea As SizeF) As PointF
  609.             Dim MyPoint As PointF
  610.             Select Case SF.Alignment
  611.                 Case StringAlignment.Center
  612.                     MyPoint.X = CSng((Area.Width - ImageArea.Width) / 2)
  613.                 Case StringAlignment.Near
  614.                     MyPoint.X = 2
  615.                 Case StringAlignment.Far
  616.                     MyPoint.X = Area.Width - ImageArea.Width - 2
  617.  
  618.             End Select
  619.  
  620.             Select Case SF.LineAlignment
  621.                 Case StringAlignment.Center
  622.                     MyPoint.Y = CSng((Area.Height - ImageArea.Height) / 2)
  623.                 Case StringAlignment.Near
  624.                     MyPoint.Y = 2
  625.                 Case StringAlignment.Far
  626.                     MyPoint.Y = Area.Height - ImageArea.Height - 2
  627.             End Select
  628.             Return MyPoint
  629.         End Function
  630.  
  631.         Private Function GetStringFormat(ByVal _ContentAlignment As ContentAlignment) As StringFormat
  632.             Dim SF As StringFormat = New StringFormat()
  633.             Select Case _ContentAlignment
  634.                 Case ContentAlignment.MiddleCenter
  635.                     SF.LineAlignment = StringAlignment.Center
  636.                     SF.Alignment = StringAlignment.Center
  637.                 Case ContentAlignment.MiddleLeft
  638.                     SF.LineAlignment = StringAlignment.Center
  639.                     SF.Alignment = StringAlignment.Near
  640.                 Case ContentAlignment.MiddleRight
  641.                     SF.LineAlignment = StringAlignment.Center
  642.                     SF.Alignment = StringAlignment.Far
  643.                 Case ContentAlignment.TopCenter
  644.                     SF.LineAlignment = StringAlignment.Near
  645.                     SF.Alignment = StringAlignment.Center
  646.                 Case ContentAlignment.TopLeft
  647.                     SF.LineAlignment = StringAlignment.Near
  648.                     SF.Alignment = StringAlignment.Near
  649.                 Case ContentAlignment.TopRight
  650.                     SF.LineAlignment = StringAlignment.Near
  651.                     SF.Alignment = StringAlignment.Far
  652.                 Case ContentAlignment.BottomCenter
  653.                     SF.LineAlignment = StringAlignment.Far
  654.                     SF.Alignment = StringAlignment.Center
  655.                 Case ContentAlignment.BottomLeft
  656.                     SF.LineAlignment = StringAlignment.Far
  657.                     SF.Alignment = StringAlignment.Near
  658.                 Case ContentAlignment.BottomRight
  659.                     SF.LineAlignment = StringAlignment.Far
  660.                     SF.Alignment = StringAlignment.Far
  661.             End Select
  662.             Return SF
  663.         End Function
  664.  
  665. #End Region
  666. #Region " Properties "
  667.  
  668.         Property Image() As Image
  669.             Get
  670.                 Return _Image
  671.             End Get
  672.             Set(ByVal value As Image)
  673.                 If value Is Nothing Then
  674.                     _ImageSize = Size.Empty
  675.                 Else
  676.                     _ImageSize = value.Size
  677.                 End If
  678.  
  679.                 _Image = value
  680.                 Invalidate()
  681.             End Set
  682.         End Property
  683.  
  684.         Protected ReadOnly Property ImageSize() As Size
  685.             Get
  686.                 Return _ImageSize
  687.             End Get
  688.         End Property
  689.  
  690.         Public Property ImageAlign() As ContentAlignment
  691.             Get
  692.                 Return _ImageAlign
  693.             End Get
  694.             Set(ByVal Value As ContentAlignment)
  695.                 _ImageAlign = Value
  696.                 Invalidate()
  697.             End Set
  698.         End Property
  699.  
  700.         Public Property TextAlignment As StringAlignment
  701.             Get
  702.                 Return Me._TextAlignment
  703.             End Get
  704.             Set(ByVal value As StringAlignment)
  705.                 Me._TextAlignment = value
  706.                 Me.Invalidate()
  707.             End Set
  708.         End Property
  709.  
  710.         Public Overrides Property ForeColor As Color
  711.             Get
  712.                 Return Me._TextColor
  713.             End Get
  714.             Set(ByVal value As Color)
  715.                 Me._TextColor = value
  716.                 Me.Invalidate()
  717.             End Set
  718.         End Property
  719.  
  720. #End Region
  721. #Region " EventArgs "
  722.  
  723.         Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  724.             MouseState = 0
  725.             Invalidate()
  726.             MyBase.OnMouseUp(e)
  727.         End Sub
  728.         Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  729.             MouseState = 1
  730.             Focus()
  731.             Invalidate()
  732.             MyBase.OnMouseDown(e)
  733.         End Sub
  734.  
  735.         Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  736.             MouseState = 0
  737.             Invalidate()
  738.             MyBase.OnMouseLeave(e)
  739.         End Sub
  740.  
  741.         Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
  742.             Invalidate()
  743.             MyBase.OnTextChanged(e)
  744.         End Sub
  745.  
  746. #End Region
  747.  
  748.         Sub New()
  749.             SetStyle(ControlStyles.AllPaintingInWmPaint Or _
  750.                      ControlStyles.OptimizedDoubleBuffer Or _
  751.                      ControlStyles.ResizeRedraw Or _
  752.                      ControlStyles.SupportsTransparentBackColor Or _
  753.                      ControlStyles.UserPaint, True)
  754.  
  755.             BackColor = Color.Transparent
  756.             DoubleBuffered = True
  757.             Font = New Font("Segoe UI", 12)
  758.             ForeColor = Color.FromArgb(255, 255, 255)
  759.             Size = New Size(146, 41)
  760.             _TextAlignment = StringAlignment.Center
  761.             P1 = New Pen(Color.FromArgb(181, 41, 42)) ' P1 = Border color
  762.            P3 = New Pen(Color.FromArgb(165, 37, 37))  ' P3 = Border color when pressed
  763.        End Sub
  764.  
  765.         Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
  766.             MyBase.OnResize(e)
  767.             If Width > 0 AndAlso Height > 0 Then
  768.  
  769.                 Shape = New GraphicsPath
  770.                 R1 = New Rectangle(0, 0, Width, Height)
  771.  
  772.                 InactiveGB = New LinearGradientBrush(New Rectangle(0, 0, Width, Height), Color.FromArgb(181, 41, 42), Color.FromArgb(181, 41, 42), 90.0F)
  773.                 PressedGB = New LinearGradientBrush(New Rectangle(0, 0, Width, Height), Color.FromArgb(165, 37, 37), Color.FromArgb(165, 37, 37), 90.0F)
  774.             End If
  775.  
  776.             With Shape
  777.                 .AddArc(0, 0, 10, 10, 180, 90)
  778.                 .AddArc(Width - 11, 0, 10, 10, -90, 90)
  779.                 .AddArc(Width - 11, Height - 11, 10, 10, 0, 90)
  780.                 .AddArc(0, Height - 11, 10, 10, 90, 90)
  781.                 .CloseAllFigures()
  782.             End With
  783.             Invalidate()
  784.         End Sub
  785.  
  786.         Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  787.             With e.Graphics
  788.                 .SmoothingMode = SmoothingMode.HighQuality
  789.                 Dim ipt As PointF = ImageLocation(GetStringFormat(ImageAlign), Size, ImageSize)
  790.  
  791.                 Select Case MouseState
  792.                     Case 0 'Inactive
  793.                        .FillPath(InactiveGB, Shape) ' Fill button body with InactiveGB color gradient
  794.                        .DrawPath(P1, Shape) ' Draw button border [InactiveGB]
  795.                        If IsNothing(Image) Then
  796.                             .DrawString(Text, Font, New SolidBrush(ForeColor), R1, New StringFormat() With {.Alignment = _TextAlignment, .LineAlignment = StringAlignment.Center})
  797.                         Else
  798.                             .DrawImage(_Image, ipt.X, ipt.Y, ImageSize.Width, ImageSize.Height)
  799.                             .DrawString(Text, Font, New SolidBrush(ForeColor), R1, New StringFormat() With {.Alignment = _TextAlignment, .LineAlignment = StringAlignment.Center})
  800.                         End If
  801.                     Case 1 'Pressed
  802.                        .FillPath(PressedGB, Shape) ' Fill button body with PressedGB color gradient
  803.                        .DrawPath(P3, Shape) ' Draw button border [PressedGB]
  804.  
  805.                         If IsNothing(Image) Then
  806.                             .DrawString(Text, Font, New SolidBrush(ForeColor), R1, New StringFormat() With {.Alignment = _TextAlignment, .LineAlignment = StringAlignment.Center})
  807.                         Else
  808.                             .DrawImage(_Image, ipt.X, ipt.Y, ImageSize.Width, ImageSize.Height)
  809.                             .DrawString(Text, Font, New SolidBrush(ForeColor), R1, New StringFormat() With {.Alignment = _TextAlignment, .LineAlignment = StringAlignment.Center})
  810.                         End If
  811.                 End Select
  812.             End With
  813.             MyBase.OnPaint(e)
  814.         End Sub
  815.     End Class
  816.  
  817. #End Region
  818. #Region " Social Button "
  819.  
  820.     Class MonoFlat_SocialButton
  821.         Inherits Control
  822.  
  823. #Region " Variables "
  824.  
  825.         Private _Image As Image
  826.         Private _ImageSize As Size
  827.         Private EllipseColor As Color = Color.FromArgb(66, 76, 85)
  828.  
  829. #End Region
  830. #Region " Properties "
  831.  
  832.         Property Image() As Image
  833.             Get
  834.                 Return _Image
  835.             End Get
  836.             Set(ByVal value As Image)
  837.                 If value Is Nothing Then
  838.                     _ImageSize = Size.Empty
  839.                 Else
  840.                     _ImageSize = value.Size
  841.                 End If
  842.  
  843.                 _Image = value
  844.                 Invalidate()
  845.             End Set
  846.         End Property
  847.  
  848.         Protected ReadOnly Property ImageSize() As Size
  849.             Get
  850.                 Return _ImageSize
  851.             End Get
  852.         End Property
  853.  
  854. #End Region
  855. #Region " EventArgs "
  856.  
  857.         Protected Overrides Sub OnResize(ByVal e As EventArgs)
  858.             MyBase.OnResize(e)
  859.             Me.Size = New Size(54, 54)
  860.         End Sub
  861.  
  862.         Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  863.             MyBase.OnMouseEnter(e)
  864.             EllipseColor = Color.FromArgb(181, 41, 42)
  865.             Refresh()
  866.         End Sub
  867.         Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  868.             MyBase.OnMouseLeave(e)
  869.             EllipseColor = Color.FromArgb(66, 76, 85)
  870.             Refresh()
  871.         End Sub
  872.  
  873.         Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  874.             MyBase.OnMouseDown(e)
  875.             EllipseColor = Color.FromArgb(153, 34, 34)
  876.             Focus()
  877.             Refresh()
  878.         End Sub
  879.         Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  880.             MyBase.OnMouseUp(e)
  881.             EllipseColor = Color.FromArgb(181, 41, 42)
  882.             Refresh()
  883.         End Sub
  884.  
  885. #End Region
  886. #Region " Image Designer "
  887.  
  888.         Private Shared Function ImageLocation(ByVal SF As StringFormat, ByVal Area As SizeF, ByVal ImageArea As SizeF) As PointF
  889.             Dim MyPoint As PointF
  890.             Select Case SF.Alignment
  891.                 Case StringAlignment.Center
  892.                     MyPoint.X = CSng((Area.Width - ImageArea.Width) / 2)
  893.             End Select
  894.  
  895.             Select Case SF.LineAlignment
  896.                 Case StringAlignment.Center
  897.                     MyPoint.Y = CSng((Area.Height - ImageArea.Height) / 2)
  898.             End Select
  899.             Return MyPoint
  900.         End Function
  901.  
  902.         Private Function GetStringFormat(ByVal _ContentAlignment As ContentAlignment) As StringFormat
  903.             Dim SF As StringFormat = New StringFormat()
  904.             Select Case _ContentAlignment
  905.                 Case ContentAlignment.MiddleCenter
  906.                     SF.LineAlignment = StringAlignment.Center
  907.                     SF.Alignment = StringAlignment.Center
  908.             End Select
  909.             Return SF
  910.         End Function
  911.  
  912. #End Region
  913.  
  914.         Sub New()
  915.             DoubleBuffered = True
  916.         End Sub
  917.  
  918.         Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  919.             Dim G As Graphics = e.Graphics
  920.             G.Clear(Parent.BackColor)
  921.             G.SmoothingMode = SmoothingMode.HighQuality
  922.  
  923.             Dim ImgPoint As PointF = ImageLocation(GetStringFormat(ContentAlignment.MiddleCenter), Size, ImageSize)
  924.             G.FillEllipse(New SolidBrush(EllipseColor), New Rectangle(0, 0, 53, 53))
  925.  
  926.             ' HINTS:
  927.            ' The best size for the drawn image is 32x32\
  928.            ' The best matching color of drawn image is (RGB: 31, 40, 49)
  929.            If Image IsNot Nothing Then
  930.                 G.DrawImage(_Image, ImgPoint.X, ImgPoint.Y, ImageSize.Width, ImageSize.Height)
  931.             End If
  932.         End Sub
  933.     End Class
  934.  
  935. #End Region
  936. #Region " Label "
  937.  
  938.     Class MonoFlat_Label
  939.         Inherits Label
  940.  
  941.         Sub New()
  942.             Font = New Font("Segoe UI", 9)
  943.             ForeColor = Color.FromArgb(116, 125, 132)
  944.             BackColor = Color.Transparent
  945.         End Sub
  946.     End Class
  947.  
  948. #End Region
  949. #Region " Link Label "
  950.     Class MonoFlat_LinkLabel
  951.         Inherits LinkLabel
  952.  
  953.         Sub New()
  954.             Font = New Font("Segoe UI", 9, FontStyle.Regular)
  955.             BackColor = Color.Transparent
  956.             LinkColor = Color.FromArgb(181, 41, 42)
  957.             ActiveLinkColor = Color.FromArgb(153, 34, 34)
  958.             VisitedLinkColor = Color.FromArgb(181, 41, 42)
  959.             LinkBehavior = Windows.Forms.LinkBehavior.NeverUnderline
  960.         End Sub
  961.     End Class
  962.  
  963. #End Region
  964. #Region " Header Label "
  965.  
  966.     Class MonoFlat_HeaderLabel
  967.         Inherits Label
  968.  
  969.         Sub New()
  970.             Font = New Font("Segoe UI", 11, FontStyle.Bold)
  971.             ForeColor = Color.FromArgb(255, 255, 255)
  972.             BackColor = Color.Transparent
  973.         End Sub
  974.     End Class
  975.  
  976. #End Region
  977. #Region " Toggle Button "
  978.  
  979.     <DefaultEvent("ToggledChanged")> Class MonoFlat_Toggle
  980.         Inherits Control
  981.  
  982. #Region " Enums "
  983.  
  984.         Enum _Type
  985.             CheckMark
  986.             OnOff
  987.             YesNo
  988.             IO
  989.         End Enum
  990.  
  991. #End Region
  992. #Region " Variables "
  993.  
  994.         Event ToggledChanged()
  995.         Private _Toggled As Boolean
  996.         Private ToggleType As _Type
  997.         Private Bar As Rectangle
  998.         Private _Width, _Height As Integer
  999.  
  1000. #End Region
  1001. #Region " Properties "
  1002.  
  1003.         Public Property Toggled() As Boolean
  1004.             Get
  1005.                 Return _Toggled
  1006.             End Get
  1007.             Set(ByVal value As Boolean)
  1008.                 _Toggled = value
  1009.                 Invalidate()
  1010.                 RaiseEvent ToggledChanged()
  1011.             End Set
  1012.         End Property
  1013.  
  1014.         Public Property Type As _Type
  1015.             Get
  1016.                 Return ToggleType
  1017.             End Get
  1018.             Set(ByVal value As _Type)
  1019.                 ToggleType = value
  1020.                 Invalidate()
  1021.             End Set
  1022.         End Property
  1023.  
  1024. #End Region
  1025. #Region " EventArgs "
  1026.  
  1027.         Protected Overrides Sub OnResize(ByVal e As EventArgs)
  1028.             MyBase.OnResize(e)
  1029.             Me.Size = New Size(76, 33)
  1030.         End Sub
  1031.  
  1032.         Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  1033.             MyBase.OnMouseUp(e)
  1034.             Toggled = Not Toggled
  1035.             Focus()
  1036.         End Sub
  1037.  
  1038. #End Region
  1039.  
  1040.         Sub New()
  1041.             SetStyle(ControlStyles.AllPaintingInWmPaint Or _
  1042.                       ControlStyles.DoubleBuffer Or _
  1043.                       ControlStyles.ResizeRedraw Or _
  1044.                       ControlStyles.UserPaint, True)
  1045.         End Sub
  1046.  
  1047.         Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  1048.             MyBase.OnPaint(e)
  1049.             Dim G As Graphics = e.Graphics
  1050.  
  1051.             G.SmoothingMode = SmoothingMode.HighQuality
  1052.             G.Clear(Parent.BackColor)
  1053.             _Width = Width - 1 : _Height = Height - 1
  1054.  
  1055.             Dim GP, GP2 As New GraphicsPath
  1056.             Dim BaseRect As New Rectangle(0, 0, _Width, _Height)
  1057.             Dim ThumbRect As New Rectangle(CInt(_Width \ 2), 0, 38, _Height)
  1058.  
  1059.             With G
  1060.                 .SmoothingMode = 2
  1061.                 .PixelOffsetMode = 2
  1062.                 .TextRenderingHint = 5
  1063.                 .Clear(BackColor)
  1064.  
  1065.                 GP = RoundRect(BaseRect, 4)
  1066.                 ThumbRect = New Rectangle(4, 4, 36, _Height - 8)
  1067.                 GP2 = RoundRect(ThumbRect, 4)
  1068.                 .FillPath(New SolidBrush(Color.FromArgb(66, 76, 85)), GP)
  1069.                 .FillPath(New SolidBrush(Color.FromArgb(32, 41, 50)), GP2)
  1070.  
  1071.                 If _Toggled Then
  1072.                     GP = RoundRect(BaseRect, 4)
  1073.                     ThumbRect = New Rectangle(CInt(_Width \ 2) - 2, 4, 36, _Height - 8)
  1074.                     GP2 = RoundRect(ThumbRect, 4)
  1075.                     .FillPath(New SolidBrush(Color.FromArgb(181, 41, 42)), GP)
  1076.                     .FillPath(New SolidBrush(Color.FromArgb(32, 41, 50)), GP2)
  1077.                 End If
  1078.  
  1079.                 ' Draw string
  1080.                Select Case ToggleType
  1081.                     Case _Type.CheckMark
  1082.                         If Toggled Then
  1083.                             G.DrawString("ü", New Font("Wingdings", 18, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, Bar.Y + 19, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  1084.                         Else
  1085.                             G.DrawString("r", New Font("Marlett", 14, FontStyle.Regular), Brushes.DimGray, Bar.X + 59, Bar.Y + 18, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  1086.                         End If
  1087.                     Case _Type.OnOff
  1088.                         If Toggled Then
  1089.                             G.DrawString("ON", New Font("Segoe UI", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, Bar.Y + 16, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  1090.                         Else
  1091.                             G.DrawString("OFF", New Font("Segoe UI", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 57, Bar.Y + 16, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  1092.                         End If
  1093.                     Case _Type.YesNo
  1094.                         If Toggled Then
  1095.                             G.DrawString("YES", New Font("Segoe UI", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 19, Bar.Y + 16, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  1096.                         Else
  1097.                             G.DrawString("NO", New Font("Segoe UI", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 56, Bar.Y + 16, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  1098.                         End If
  1099.                     Case _Type.IO
  1100.                         If Toggled Then
  1101.                             G.DrawString("I", New Font("Segoe UI", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, Bar.Y + 16, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  1102.                         Else
  1103.                             G.DrawString("O", New Font("Segoe UI", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 57, Bar.Y + 16, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  1104.                         End If
  1105.                 End Select
  1106.             End With
  1107.         End Sub
  1108.     End Class
  1109.  
  1110. #End Region
  1111. #Region " CheckBox "
  1112.  
  1113.     <DefaultEvent("CheckedChanged")> Class MonoFlat_CheckBox
  1114.         Inherits Control
  1115.  
  1116. #Region " Variables "
  1117.  
  1118.         Private X As Integer
  1119.         Private _Checked As Boolean = False
  1120.         Private Shape As GraphicsPath
  1121.  
  1122. #End Region
  1123. #Region " Properties "
  1124.  
  1125.         Property Checked() As Boolean
  1126.             Get
  1127.                 Return _Checked
  1128.             End Get
  1129.             Set(ByVal value As Boolean)
  1130.                 _Checked = value
  1131.                 Invalidate()
  1132.             End Set
  1133.         End Property
  1134.  
  1135. #End Region
  1136. #Region " EventArgs "
  1137.  
  1138.         Event CheckedChanged(ByVal sender As Object)
  1139.  
  1140.         Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  1141.             MyBase.OnMouseMove(e)
  1142.             X = e.Location.X
  1143.             Invalidate()
  1144.         End Sub
  1145.         Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  1146.             _Checked = Not _Checked
  1147.             Focus()
  1148.             RaiseEvent CheckedChanged(Me)
  1149.             MyBase.OnMouseDown(e)
  1150.         End Sub
  1151.  
  1152.         Protected Overrides Sub OnResize(ByVal e As EventArgs)
  1153.             MyBase.OnResize(e)
  1154.  
  1155.             Me.Height = 16
  1156.  
  1157.             Shape = New GraphicsPath
  1158.             With Shape
  1159.                 .AddArc(0, 0, 10, 10, 180, 90)
  1160.                 .AddArc(Width - 11, 0, 10, 10, -90, 90)
  1161.                 .AddArc(Width - 11, Height - 11, 10, 10, 0, 90)
  1162.                 .AddArc(0, Height - 11, 10, 10, 90, 90)
  1163.                 .CloseAllFigures()
  1164.             End With
  1165.             Invalidate()
  1166.         End Sub
  1167.  
  1168. #End Region
  1169.  
  1170.         Sub New()
  1171.             Width = 148
  1172.             Height = 16
  1173.             Font = New Font("Microsoft Sans Serif", 9)
  1174.             DoubleBuffered = True
  1175.         End Sub
  1176.  
  1177.         Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  1178.             MyBase.OnPaint(e)
  1179.             Dim G As Graphics = e.Graphics
  1180.             G.Clear(Parent.BackColor)
  1181.  
  1182.             If _Checked Then
  1183.                 G.FillRectangle(New SolidBrush(Color.FromArgb(66, 76, 85)), New Rectangle(0, 0, 16, 16))
  1184.                 G.FillRectangle(New SolidBrush(Color.FromArgb(66, 76, 85)), New Rectangle(1, 1, 16 - 2, 16 - 2))
  1185.             Else
  1186.                 G.FillRectangle(New SolidBrush(Color.FromArgb(66, 76, 85)), New Rectangle(0, 0, 16, 16))
  1187.                 G.FillRectangle(New SolidBrush(Color.FromArgb(66, 76, 85)), New Rectangle(1, 1, 16 - 2, 16 - 2))
  1188.             End If
  1189.  
  1190.             If Enabled = True Then
  1191.                 If _Checked Then G.DrawString("a", New Font("Marlett", 16), New SolidBrush(Color.FromArgb(181, 41, 42)), New Point(-5, -3))
  1192.             Else
  1193.                 If _Checked Then G.DrawString("a", New Font("Marlett", 16), New SolidBrush(Color.Gray), New Point(-5, -3))
  1194.             End If
  1195.  
  1196.             G.DrawString(Text, Font, New SolidBrush(Color.FromArgb(116, 125, 132)), New Point(20, 0))
  1197.         End Sub
  1198.     End Class
  1199. #End Region
  1200. #Region " Radio Button "
  1201.  
  1202.     <DefaultEvent("CheckedChanged")> Class MonoFlat_RadioButton
  1203.         Inherits Control
  1204.  
  1205. #Region " Variables "
  1206.  
  1207.         Private X As Integer
  1208.         Private _Checked As Boolean
  1209.  
  1210. #End Region
  1211. #Region " Properties "
  1212.  
  1213.         Property Checked() As Boolean
  1214.             Get
  1215.                 Return _Checked
  1216.             End Get
  1217.             Set(ByVal value As Boolean)
  1218.                 _Checked = value
  1219.                 InvalidateControls()
  1220.                 RaiseEvent CheckedChanged(Me)
  1221.                 Invalidate()
  1222.             End Set
  1223.         End Property
  1224.  
  1225. #End Region
  1226. #Region " EventArgs "
  1227.  
  1228.         Event CheckedChanged(ByVal sender As Object)
  1229.  
  1230.         Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  1231.             If Not _Checked Then Checked = True
  1232.             Focus()
  1233.             MyBase.OnMouseDown(e)
  1234.         End Sub
  1235.         Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  1236.             MyBase.OnMouseMove(e)
  1237.             X = e.X
  1238.             Invalidate()
  1239.         End Sub
  1240.         Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
  1241.             MyBase.OnTextChanged(e)
  1242.             Dim textSize As Integer
  1243.             textSize = Me.CreateGraphics.MeasureString(Text, Font).Width
  1244.             Me.Width = 28 + textSize
  1245.         End Sub
  1246.  
  1247.         Protected Overrides Sub OnResize(ByVal e As EventArgs)
  1248.             MyBase.OnResize(e)
  1249.             Me.Height = 17
  1250.         End Sub
  1251.  
  1252. #End Region
  1253.  
  1254.         Public Sub New()
  1255.             Width = 159
  1256.             Height = 17
  1257.             DoubleBuffered = True
  1258.         End Sub
  1259.  
  1260.         Private Sub InvalidateControls()
  1261.             If Not IsHandleCreated OrElse Not _Checked Then Return
  1262.  
  1263.             For Each _Control As Control In Parent.Controls
  1264.                 If _Control IsNot Me AndAlso TypeOf _Control Is MonoFlat_RadioButton Then
  1265.                     DirectCast(_Control, MonoFlat_RadioButton).Checked = False
  1266.                 End If
  1267.             Next
  1268.         End Sub
  1269.  
  1270.         Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  1271.             MyBase.OnPaint(e)
  1272.             Dim G As Graphics = e.Graphics
  1273.             G.Clear(Parent.BackColor)
  1274.             G.SmoothingMode = SmoothingMode.HighQuality
  1275.  
  1276.             G.FillEllipse(New SolidBrush(Color.FromArgb(66, 76, 85)), New Rectangle(0, 0, 16, 16))
  1277.  
  1278.             If _Checked Then
  1279.                 G.DrawString("a", New Font("Marlett", 15), New SolidBrush(Color.FromArgb(181, 41, 42)), New Point(-3, -2))
  1280.             End If
  1281.  
  1282.             G.DrawString(Text, Font, New SolidBrush(Color.FromArgb(116, 125, 132)), New Point(20, 0))
  1283.         End Sub
  1284.     End Class
  1285.  
  1286. #End Region
  1287. #Region " TextBox "
  1288.  
  1289.     <DefaultEvent("TextChanged")> Class MonoFlat_TextBox
  1290.         Inherits Control
  1291.  
  1292. #Region " Variables "
  1293.  
  1294.         Public WithEvents MonoFlatTB As New TextBox
  1295.         Private _maxchars As Integer = 32767
  1296.         Private _ReadOnly As Boolean
  1297.         Private _Multiline As Boolean
  1298.         Private _Image As Image
  1299.         Private _ImageSize As Size
  1300.         Private ALNType As HorizontalAlignment
  1301.         Private isPasswordMasked As Boolean = False
  1302.         Private P1 As Pen
  1303.         Private B1 As SolidBrush
  1304.         Private Shape As GraphicsPath
  1305.  
  1306. #End Region
  1307. #Region " Properties "
  1308.  
  1309.         Public Shadows Property TextAlignment() As HorizontalAlignment
  1310.             Get
  1311.                 Return ALNType
  1312.             End Get
  1313.             Set(ByVal Val As HorizontalAlignment)
  1314.                 ALNType = Val
  1315.                 Invalidate()
  1316.             End Set
  1317.         End Property
  1318.         Public Shadows Property MaxLength() As Integer
  1319.             Get
  1320.                 Return _maxchars
  1321.             End Get
  1322.             Set(ByVal Val As Integer)
  1323.                 _maxchars = Val
  1324.                 MonoFlatTB.MaxLength = MaxLength
  1325.                 Invalidate()
  1326.             End Set
  1327.         End Property
  1328.  
  1329.         Public Shadows Property UseSystemPasswordChar() As Boolean
  1330.             Get
  1331.                 Return isPasswordMasked
  1332.             End Get
  1333.             Set(ByVal Val As Boolean)
  1334.                 MonoFlatTB.UseSystemPasswordChar = UseSystemPasswordChar
  1335.                 isPasswordMasked = Val
  1336.                 Invalidate()
  1337.             End Set
  1338.         End Property
  1339.         Property [ReadOnly]() As Boolean
  1340.             Get
  1341.                 Return _ReadOnly
  1342.             End Get
  1343.             Set(ByVal value As Boolean)
  1344.                 _ReadOnly = value
  1345.                 If MonoFlatTB IsNot Nothing Then
  1346.                     MonoFlatTB.ReadOnly = value
  1347.                 End If
  1348.             End Set
  1349.         End Property
  1350.         Property Multiline() As Boolean
  1351.             Get
  1352.                 Return _Multiline
  1353.             End Get
  1354.             Set(ByVal value As Boolean)
  1355.                 _Multiline = value
  1356.                 If MonoFlatTB IsNot Nothing Then
  1357.                     MonoFlatTB.Multiline = value
  1358.  
  1359.                     If value Then
  1360.                         MonoFlatTB.Height = Height - 23
  1361.                     Else
  1362.                         Height = MonoFlatTB.Height + 23
  1363.                     End If
  1364.                 End If
  1365.             End Set
  1366.         End Property
  1367.  
  1368.         Property Image() As Image
  1369.             Get
  1370.                 Return _Image
  1371.             End Get
  1372.             Set(ByVal value As Image)
  1373.                 If value Is Nothing Then
  1374.                     _ImageSize = Size.Empty
  1375.                 Else
  1376.                     _ImageSize = value.Size
  1377.                 End If
  1378.  
  1379.                 _Image = value
  1380.  
  1381.                 If Image Is Nothing Then
  1382.                     MonoFlatTB.Location = New Point(8, 10)
  1383.                 Else
  1384.                     MonoFlatTB.Location = New Point(35, 11)
  1385.                 End If
  1386.                 Invalidate()
  1387.             End Set
  1388.         End Property
  1389.  
  1390.         Protected ReadOnly Property ImageSize() As Size
  1391.             Get
  1392.                 Return _ImageSize
  1393.             End Get
  1394.         End Property
  1395.  
  1396. #End Region
  1397. #Region " EventArgs "
  1398.  
  1399.         Private Sub _Enter(ByVal Obj As Object, ByVal e As EventArgs)
  1400.             P1 = New Pen(Color.FromArgb(181, 41, 42))
  1401.             Refresh()
  1402.         End Sub
  1403.  
  1404.         Private Sub _Leave(ByVal Obj As Object, ByVal e As EventArgs)
  1405.             P1 = New Pen(Color.FromArgb(32, 41, 50))
  1406.             Refresh()
  1407.         End Sub
  1408.  
  1409.         Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
  1410.             MyBase.OnTextChanged(e)
  1411.             Invalidate()
  1412.         End Sub
  1413.  
  1414.         Protected Overrides Sub OnForeColorChanged(ByVal e As System.EventArgs)
  1415.             MyBase.OnForeColorChanged(e)
  1416.             MonoFlatTB.ForeColor = ForeColor
  1417.             Invalidate()
  1418.         End Sub
  1419.  
  1420.         Protected Overrides Sub OnFontChanged(ByVal e As System.EventArgs)
  1421.             MyBase.OnFontChanged(e)
  1422.             MonoFlatTB.Font = Font
  1423.         End Sub
  1424.  
  1425.         Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
  1426.             MyBase.OnPaintBackground(e)
  1427.         End Sub
  1428.  
  1429.         Private Sub _OnKeyDown(ByVal Obj As Object, ByVal e As KeyEventArgs)
  1430.             If e.Control AndAlso e.KeyCode = Keys.A Then
  1431.                 MonoFlatTB.SelectAll()
  1432.                 e.SuppressKeyPress = True
  1433.             End If
  1434.             If e.Control AndAlso e.KeyCode = Keys.C Then
  1435.                 MonoFlatTB.Copy()
  1436.                 e.SuppressKeyPress = True
  1437.             End If
  1438.         End Sub
  1439.  
  1440.         Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
  1441.             MyBase.OnResize(e)
  1442.             If _Multiline Then
  1443.                 MonoFlatTB.Height = Height - 23
  1444.             Else
  1445.                 Height = MonoFlatTB.Height + 23
  1446.             End If
  1447.  
  1448.             Shape = New GraphicsPath
  1449.             With Shape
  1450.                 .AddArc(0, 0, 10, 10, 180, 90)
  1451.                 .AddArc(Width - 11, 0, 10, 10, -90, 90)
  1452.                 .AddArc(Width - 11, Height - 11, 10, 10, 0, 90)
  1453.                 .AddArc(0, Height - 11, 10, 10, 90, 90)
  1454.                 .CloseAllFigures()
  1455.             End With
  1456.         End Sub
  1457.  
  1458.         Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
  1459.             MyBase.OnGotFocus(e)
  1460.             MonoFlatTB.Focus()
  1461.         End Sub
  1462.  
  1463.         Sub _TextChanged() Handles MonoFlatTB.TextChanged
  1464.             Text = MonoFlatTB.Text
  1465.         End Sub
  1466.  
  1467.         Sub _BaseTextChanged() Handles MyBase.TextChanged
  1468.             MonoFlatTB.Text = Text
  1469.         End Sub
  1470.  
  1471. #End Region
  1472.  
  1473.         Sub AddTextBox()
  1474.             With MonoFlatTB
  1475.                 .Location = New Point(8, 10)
  1476.                 .Text = String.Empty
  1477.                 .BorderStyle = BorderStyle.None
  1478.                 .TextAlign = HorizontalAlignment.Left
  1479.                 .Font = New Font("Tahoma", 11)
  1480.                 .UseSystemPasswordChar = UseSystemPasswordChar
  1481.                 .Multiline = False
  1482.                 .BackColor = Color.FromArgb(66, 76, 85)
  1483.                 .ScrollBars = ScrollBars.None
  1484.             End With
  1485.             AddHandler MonoFlatTB.KeyDown, AddressOf _OnKeyDown
  1486.             AddHandler MonoFlatTB.Enter, AddressOf _Enter
  1487.             AddHandler MonoFlatTB.Leave, AddressOf _Leave
  1488.         End Sub
  1489.  
  1490.         Sub New()
  1491.             SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  1492.             SetStyle(ControlStyles.UserPaint, True)
  1493.  
  1494.             AddTextBox()
  1495.             Controls.Add(MonoFlatTB)
  1496.  
  1497.             P1 = New Pen(Color.FromArgb(32, 41, 50))
  1498.             B1 = New SolidBrush(Color.FromArgb(66, 76, 85))
  1499.             BackColor = Color.Transparent
  1500.             ForeColor = Color.FromArgb(176, 183, 191)
  1501.  
  1502.             Text = Nothing
  1503.             Font = New Font("Tahoma", 11)
  1504.             Size = New Size(135, 43)
  1505.             DoubleBuffered = True
  1506.         End Sub
  1507.  
  1508.         Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  1509.             MyBase.OnPaint(e)
  1510.             Dim B As New Bitmap(Width, Height)
  1511.             Dim G As Graphics = Graphics.FromImage(B)
  1512.  
  1513.             G.SmoothingMode = SmoothingMode.AntiAlias
  1514.  
  1515.             With MonoFlatTB
  1516.  
  1517.                 If Image Is Nothing Then
  1518.                     .Width = Width - 18
  1519.                 Else
  1520.                     .Width = Width - 45
  1521.                 End If
  1522.  
  1523.                 .TextAlign = TextAlignment
  1524.                 .UseSystemPasswordChar = UseSystemPasswordChar
  1525.             End With
  1526.  
  1527.             G.Clear(Color.Transparent)
  1528.  
  1529.             G.FillPath(B1, Shape)
  1530.             G.DrawPath(P1, Shape)
  1531.  
  1532.             If Image IsNot Nothing Then
  1533.                 G.DrawImage(_Image, 5, 8, 24, 24)
  1534.                 ' 24x24 is the perfect size of the image
  1535.            End If
  1536.  
  1537.             e.Graphics.DrawImage(B.Clone(), 0, 0)
  1538.             G.Dispose() : B.Dispose()
  1539.         End Sub
  1540.     End Class
  1541.  
  1542. #End Region
  1543. #Region " Panel "
  1544.  
  1545.     Class MonoFlat_Panel
  1546.         Inherits ContainerControl
  1547.  
  1548.         Private Shape As GraphicsPath
  1549.  
  1550.         Sub New()
  1551.             SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  1552.             SetStyle(ControlStyles.UserPaint, True)
  1553.  
  1554.             BackColor = Color.FromArgb(39, 51, 63)
  1555.             Me.Size = New Size(187, 117)
  1556.             Padding = New Padding(5, 5, 5, 5)
  1557.             DoubleBuffered = True
  1558.         End Sub
  1559.  
  1560.         Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
  1561.             MyBase.OnResize(e)
  1562.  
  1563.             Shape = New GraphicsPath
  1564.             With Shape
  1565.                 .AddArc(0, 0, 10, 10, 180, 90)
  1566.                 .AddArc(Width - 11, 0, 10, 10, -90, 90)
  1567.                 .AddArc(Width - 11, Height - 11, 10, 10, 0, 90)
  1568.                 .AddArc(0, Height - 11, 10, 10, 90, 90)
  1569.                 .CloseAllFigures()
  1570.             End With
  1571.         End Sub
  1572.  
  1573.         Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  1574.             MyBase.OnPaint(e)
  1575.             Dim B As New Bitmap(Width, Height)
  1576.             Dim G = Graphics.FromImage(B)
  1577.  
  1578.             G.SmoothingMode = SmoothingMode.HighQuality
  1579.  
  1580.             G.Clear(Color.FromArgb(32, 41, 50)) ' Set control background to transparent
  1581.            G.FillPath(New SolidBrush(Color.FromArgb(39, 51, 63)), Shape) ' Draw RTB background
  1582.            G.DrawPath(New Pen(Color.FromArgb(39, 51, 63)), Shape) ' Draw border
  1583.  
  1584.             G.Dispose()
  1585.             e.Graphics.DrawImage(B.Clone(), 0, 0)
  1586.             B.Dispose()
  1587.         End Sub
  1588.     End Class
  1589.  
  1590. #End Region
  1591. #Region " Separator "
  1592.  
  1593.     Class MonoFlat_Separator
  1594.         Inherits Control
  1595.  
  1596.         Sub New()
  1597.             SetStyle(ControlStyles.ResizeRedraw, True)
  1598.             Me.Size = New Point(120, 10)
  1599.         End Sub
  1600.  
  1601.         Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  1602.             MyBase.OnPaint(e)
  1603.             e.Graphics.DrawLine(New Pen(Color.FromArgb(45, 57, 68)), 0, 5, Width, 5)
  1604.         End Sub
  1605.     End Class
  1606.  
  1607. #End Region
  1608. #Region " TrackBar "
  1609.  
  1610.     <DefaultEvent("ValueChanged")> Class MonoFlat_TrackBar
  1611.         Inherits Control
  1612.  
  1613. #Region " Enums "
  1614.  
  1615.         Enum ValueDivisor
  1616.             By1 = 1
  1617.             By10 = 10
  1618.             By100 = 100
  1619.             By1000 = 1000
  1620.         End Enum
  1621.  
  1622. #End Region
  1623. #Region " Variables "
  1624.  
  1625.         Private FillValue, PipeBorder, TrackBarHandleRect As Rectangle
  1626.         Private Cap As Boolean
  1627.         Private ValueDrawer As Integer
  1628.  
  1629.         Private ThumbSize As Size = New Size(14, 14)
  1630.         Private TrackThumb As Rectangle
  1631.  
  1632.         Private _Minimum As Integer = 0
  1633.         Private _Maximum As Integer = 10
  1634.         Private _Value As Integer = 0
  1635.  
  1636.         Private _JumpToMouse As Boolean = False
  1637.         Private DividedValue As ValueDivisor = ValueDivisor.By1
  1638.  
  1639. #End Region
  1640. #Region " Properties "
  1641.  
  1642.         Public Property Minimum() As Integer
  1643.             Get
  1644.                 Return _Minimum
  1645.             End Get
  1646.             Set(ByVal value As Integer)
  1647.  
  1648.                 If value >= _Maximum Then value = _Maximum - 10
  1649.                 If _Value < value Then _Value = value
  1650.  
  1651.                 _Minimum = value
  1652.                 Invalidate()
  1653.             End Set
  1654.         End Property
  1655.  
  1656.         Public Property Maximum() As Integer
  1657.             Get
  1658.                 Return _Maximum
  1659.             End Get
  1660.             Set(ByVal value As Integer)
  1661.  
  1662.                 If value <= _Minimum Then value = _Minimum + 10
  1663.                 If _Value > value Then _Value = value
  1664.  
  1665.                 _Maximum = value
  1666.                 Invalidate()
  1667.             End Set
  1668.         End Property
  1669.  
  1670.         Event ValueChanged()
  1671.         Public Property Value() As Integer
  1672.             Get
  1673.                 Return _Value
  1674.             End Get
  1675.             Set(ByVal value As Integer)
  1676.                 If _Value <> value Then
  1677.                     If value < _Minimum Then
  1678.                         _Value = _Minimum
  1679.                     Else
  1680.                         If value > _Maximum Then
  1681.                             _Value = _Maximum
  1682.                         Else
  1683.                             _Value = value
  1684.                         End If
  1685.                     End If
  1686.                     Invalidate()
  1687.                     RaiseEvent ValueChanged()
  1688.                 End If
  1689.             End Set
  1690.         End Property
  1691.  
  1692.         Public Property ValueDivison() As ValueDivisor
  1693.             Get
  1694.                 Return DividedValue
  1695.             End Get
  1696.             Set(ByVal Value As ValueDivisor)
  1697.                 DividedValue = Value
  1698.                 Invalidate()
  1699.             End Set
  1700.         End Property
  1701.  
  1702.         <Browsable(False)> Public Property ValueToSet() As Single
  1703.             Get
  1704.                 Return CSng(_Value / DividedValue)
  1705.             End Get
  1706.             Set(ByVal Val As Single)
  1707.                 Value = CInt(Val * DividedValue)
  1708.             End Set
  1709.         End Property
  1710.  
  1711.         Public Property JumpToMouse() As Boolean
  1712.             Get
  1713.                 Return _JumpToMouse
  1714.             End Get
  1715.             Set(ByVal value As Boolean)
  1716.                 _JumpToMouse = value
  1717.                 Invalidate()
  1718.             End Set
  1719.         End Property
  1720.  
  1721. #End Region
  1722. #Region " EventArgs "
  1723.  
  1724.         Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  1725.             MyBase.OnMouseMove(e)
  1726.             If Cap = True AndAlso e.X > -1 AndAlso e.X < (Width + 1) Then
  1727.                 Value = _Minimum + CInt((_Maximum - _Minimum) * (e.X / Width))
  1728.             End If
  1729.         End Sub
  1730.  
  1731.         Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  1732.             MyBase.OnMouseDown(e)
  1733.             If e.Button = Windows.Forms.MouseButtons.Left Then
  1734.                 ValueDrawer = CInt((_Value - _Minimum) / (_Maximum - _Minimum) * (Width - 11))
  1735.                 TrackBarHandleRect = New Rectangle(ValueDrawer, 0, 25, 25)
  1736.                 Cap = TrackBarHandleRect.Contains(e.Location)
  1737.                 Focus()
  1738.                 If _JumpToMouse Then
  1739.                     Value = _Minimum + CInt((_Maximum - _Minimum) * (e.X / Width))
  1740.                 End If
  1741.             End If
  1742.         End Sub
  1743.  
  1744.         Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  1745.             MyBase.OnMouseUp(e)
  1746.             Cap = False
  1747.         End Sub
  1748.  
  1749. #End Region
  1750.  
  1751.         Sub New()
  1752.             SetStyle(ControlStyles.AllPaintingInWmPaint Or _
  1753.              ControlStyles.UserPaint Or _
  1754.              ControlStyles.ResizeRedraw Or _
  1755.              ControlStyles.DoubleBuffer, True)
  1756.  
  1757.             Size = New Size(80, 22)
  1758.             MinimumSize = New Size(47, 22)
  1759.         End Sub
  1760.  
  1761.         Protected Overrides Sub OnResize(ByVal e As EventArgs)
  1762.             MyBase.OnResize(e)
  1763.             Height = 22
  1764.         End Sub
  1765.  
  1766.         Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  1767.             MyBase.OnPaint(e)
  1768.             Dim G As Graphics = e.Graphics
  1769.  
  1770.             G.Clear(Parent.BackColor)
  1771.             G.SmoothingMode = SmoothingMode.AntiAlias
  1772.             TrackThumb = New Rectangle(7, 10, Width - 16, 2)
  1773.             PipeBorder = New Rectangle(1, 10, Width - 3, 2)
  1774.  
  1775.             Try
  1776.                 ValueDrawer = CInt((_Value - _Minimum) / (_Maximum - _Minimum) * (Width))
  1777.             Catch ex As Exception
  1778.             End Try
  1779.  
  1780.             TrackBarHandleRect = New Rectangle(ValueDrawer, 0, 3, 20)
  1781.  
  1782.             G.FillRectangle(New SolidBrush(Color.FromArgb(124, 131, 137)), PipeBorder)
  1783.             FillValue = New Rectangle(0, 10, TrackBarHandleRect.X + TrackBarHandleRect.Width - 4, 3)
  1784.  
  1785.             G.ResetClip()
  1786.  
  1787.             G.SmoothingMode = SmoothingMode.Default
  1788.             G.DrawRectangle(New Pen(Color.FromArgb(124, 131, 137)), PipeBorder) ' Draw pipe border
  1789.            G.FillRectangle(New SolidBrush(Color.FromArgb(181, 41, 42)), FillValue)
  1790.  
  1791.             G.ResetClip()
  1792.  
  1793.             G.SmoothingMode = SmoothingMode.HighQuality
  1794.             G.FillEllipse(New SolidBrush(Color.FromArgb(181, 41, 42)), TrackThumb.X + CInt(TrackThumb.Width * (Value / Maximum)) - CInt(ThumbSize.Width / 2), TrackThumb.Y + CInt((TrackThumb.Height / 2)) - CInt(ThumbSize.Height / 2), ThumbSize.Width, ThumbSize.Height)
  1795.             G.DrawEllipse(New Pen(Color.FromArgb(181, 41, 42)), TrackThumb.X + CInt(TrackThumb.Width * (Value / Maximum)) - CInt(ThumbSize.Width / 2), TrackThumb.Y + CInt((TrackThumb.Height / 2)) - CInt(ThumbSize.Height / 2), ThumbSize.Width, ThumbSize.Height)
  1796.         End Sub
  1797.     End Class
  1798.  
  1799. #End Region
  1800. #Region " NotificationBox "
  1801.  
  1802.     Class MonoFlat_NotificationBox
  1803.         Inherits Control
  1804.  
  1805. #Region " Variables "
  1806.  
  1807.         Private CloseCoordinates As Point
  1808.         Private IsOverClose As Boolean
  1809.         Private _BorderCurve As Integer = 8
  1810.         Private CreateRoundPath As GraphicsPath
  1811.         Private NotificationText As String = Nothing
  1812.         Private _NotificationType As Type
  1813.         Private _RoundedCorners As Boolean
  1814.         Private _ShowCloseButton As Boolean
  1815.         Private _Image As Image
  1816.         Private _ImageSize As Size
  1817.  
  1818. #End Region
  1819. #Region " Enums "
  1820.  
  1821.         ' Create a list of Notification Types
  1822.        Enum Type
  1823.             [Notice]
  1824.             [Success]
  1825.             [Warning]
  1826.             [Error]
  1827.         End Enum
  1828.  
  1829. #End Region
  1830. #Region " Custom Properties "
  1831.  
  1832.         ' Create a NotificationType property and add the Type enum to it
  1833.        Public Property NotificationType As Type
  1834.             Get
  1835.                 Return _NotificationType
  1836.             End Get
  1837.             Set(ByVal value As Type)
  1838.                 _NotificationType = value
  1839.                 Invalidate()
  1840.             End Set
  1841.         End Property
  1842.         ' Boolean value to determine whether the control should use border radius
  1843.        Public Property RoundCorners As Boolean
  1844.             Get
  1845.                 Return _RoundedCorners
  1846.             End Get
  1847.             Set(ByVal value As Boolean)
  1848.                 _RoundedCorners = value
  1849.                 Invalidate()
  1850.             End Set
  1851.         End Property
  1852.         ' Boolean value to determine whether the control should draw the close button
  1853.        Public Property ShowCloseButton As Boolean
  1854.             Get
  1855.                 Return _ShowCloseButton
  1856.             End Get
  1857.             Set(ByVal value As Boolean)
  1858.                 _ShowCloseButton = value
  1859.                 Invalidate()
  1860.             End Set
  1861.         End Property
  1862.         ' Integer value to determine the curve level of the borders
  1863.        Public Property BorderCurve As Integer
  1864.             Get
  1865.                 Return _BorderCurve
  1866.             End Get
  1867.             Set(ByVal value As Integer)
  1868.                 _BorderCurve = value
  1869.                 Invalidate()
  1870.             End Set
  1871.         End Property
  1872.         ' Image value to determine whether the control should draw an image before the header
  1873.        Property Image() As Image
  1874.             Get
  1875.                 Return _Image
  1876.             End Get
  1877.             Set(ByVal value As Image)
  1878.                 If value Is Nothing Then
  1879.                     _ImageSize = Size.Empty
  1880.                 Else
  1881.                     _ImageSize = value.Size
  1882.                 End If
  1883.  
  1884.                 _Image = value
  1885.                 Invalidate()
  1886.             End Set
  1887.         End Property
  1888.         ' Size value - returns the image size
  1889.        Protected ReadOnly Property ImageSize() As Size
  1890.             Get
  1891.                 Return _ImageSize
  1892.             End Get
  1893.         End Property
  1894.  
  1895. #End Region
  1896. #Region " EventArgs "
  1897.  
  1898.         Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  1899.             MyBase.OnMouseMove(e)
  1900.  
  1901.             ' Decides the location of the drawn ellipse. If mouse is over the correct coordinates, "IsOverClose" boolean will be triggered to draw the ellipse
  1902.            If e.X >= Width - 19 AndAlso e.X <= Width - 10 AndAlso e.Y > CloseCoordinates.Y AndAlso e.Y < CloseCoordinates.Y + 12 Then
  1903.                 IsOverClose = True
  1904.             Else
  1905.                 IsOverClose = False
  1906.             End If
  1907.             ' Updates the control
  1908.            Invalidate()
  1909.         End Sub
  1910.         Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  1911.             MyBase.OnMouseDown(e)
  1912.  
  1913.             ' Disposes the control when the close button is clicked
  1914.            If _ShowCloseButton = True Then
  1915.                 If IsOverClose Then
  1916.                     Dispose()
  1917.                 End If
  1918.             End If
  1919.         End Sub
  1920.  
  1921. #End Region
  1922.  
  1923.         Friend Function CreateRoundRect(ByVal r As Rectangle, ByVal curve As Integer) As GraphicsPath
  1924.             ' Draw a border radius
  1925.            Try
  1926.                 CreateRoundPath = New GraphicsPath(FillMode.Winding)
  1927.                 CreateRoundPath.AddArc(r.X, r.Y, curve, curve, 180.0F, 90.0F)
  1928.                 CreateRoundPath.AddArc(r.Right - curve, r.Y, curve, curve, 270.0F, 90.0F)
  1929.                 CreateRoundPath.AddArc(r.Right - curve, r.Bottom - curve, curve, curve, 0.0F, 90.0F)
  1930.                 CreateRoundPath.AddArc(r.X, r.Bottom - curve, curve, curve, 90.0F, 90.0F)
  1931.                 CreateRoundPath.CloseFigure()
  1932.             Catch ex As Exception
  1933.                 MessageBox.Show(ex.Message & vbNewLine & vbNewLine & "Value must be either '1' or higher", "Invalid Integer", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  1934.                 ' Return to the default border curve if the parameter is less than "1"
  1935.                _BorderCurve = 8
  1936.                 BorderCurve = 8
  1937.             End Try
  1938.             Return CreateRoundPath
  1939.         End Function
  1940.  
  1941.         Sub New()
  1942.             SetStyle(ControlStyles.AllPaintingInWmPaint Or _
  1943.                      ControlStyles.UserPaint Or _
  1944.                      ControlStyles.OptimizedDoubleBuffer Or _
  1945.                      ControlStyles.ResizeRedraw, True)
  1946.  
  1947.             Font = New Font("Tahoma", 9)
  1948.             Me.MinimumSize = New Size(100, 40)
  1949.             RoundCorners = False
  1950.             ShowCloseButton = True
  1951.         End Sub
  1952.  
  1953.         Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  1954.             MyBase.OnPaint(e)
  1955.  
  1956.             ' Declare Graphics to draw the control
  1957.            Dim GFX As Graphics = e.Graphics
  1958.             ' Declare Color to paint the control's Text, Background and Border
  1959.            Dim ForeColor, BackgroundColor, BorderColor As Color
  1960.             ' Determine the header Notification Type font
  1961.            Dim TypeFont As New Font(Font.FontFamily, Font.Size, FontStyle.Bold)
  1962.             ' Decalre a new rectangle to draw the control inside it
  1963.            Dim MainRectangle As New Rectangle(0, 0, Width - 1, Height - 1)
  1964.             ' Declare a GraphicsPath to create a border radius
  1965.            Dim CrvBorderPath As GraphicsPath = CreateRoundRect(MainRectangle, _BorderCurve)
  1966.  
  1967.             GFX.SmoothingMode = SmoothingMode.HighQuality
  1968.             GFX.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
  1969.             GFX.Clear(Parent.BackColor)
  1970.  
  1971.             Select Case _NotificationType
  1972.                 Case Type.Notice
  1973.                     BackgroundColor = Color.FromArgb(111, 177, 199)
  1974.                     BorderColor = Color.FromArgb(111, 177, 199)
  1975.                     ForeColor = Color.White
  1976.                 Case Type.Success
  1977.                     BackgroundColor = Color.FromArgb(91, 195, 162)
  1978.                     BorderColor = Color.FromArgb(91, 195, 162)
  1979.                     ForeColor = Color.White
  1980.                 Case Type.Warning
  1981.                     BackgroundColor = Color.FromArgb(254, 209, 108)
  1982.                     BorderColor = Color.FromArgb(254, 209, 108)
  1983.                     ForeColor = Color.DimGray
  1984.                 Case Type.Error
  1985.                     BackgroundColor = Color.FromArgb(217, 103, 93)
  1986.                     BorderColor = Color.FromArgb(217, 103, 93)
  1987.                     ForeColor = Color.White
  1988.             End Select
  1989.  
  1990.             If _RoundedCorners = True Then
  1991.                 GFX.FillPath(New SolidBrush(BackgroundColor), CrvBorderPath)
  1992.                 GFX.DrawPath(New Pen(BorderColor), CrvBorderPath)
  1993.             Else
  1994.                 GFX.FillRectangle(New SolidBrush(BackgroundColor), MainRectangle)
  1995.                 GFX.DrawRectangle(New Pen(BorderColor), MainRectangle)
  1996.             End If
  1997.  
  1998.             Select Case _NotificationType
  1999.                 Case Type.Notice
  2000.                     NotificationText = "NOTICIA #JBK"
  2001.                 Case Type.Success
  2002.                     NotificationText = "SUCESSO #JBK"
  2003.                 Case Type.Warning
  2004.                     NotificationText = "INFORMAÇÕES DA BIN:"
  2005.                 Case Type.Error
  2006.                     NotificationText = "ERRO #JBK"
  2007.             End Select
  2008.  
  2009.             If IsNothing(Image) Then
  2010.                 GFX.DrawString(NotificationText, TypeFont, New SolidBrush(ForeColor), New Point(10, 5))
  2011.                 GFX.DrawString(Text, Font, New SolidBrush(ForeColor), New Rectangle(10, 21, Width - 17, Height - 5))
  2012.             Else
  2013.                 GFX.DrawImage(_Image, 12, 4, 16, 16)
  2014.                 GFX.DrawString(NotificationText, TypeFont, New SolidBrush(ForeColor), New Point(30, 5))
  2015.                 GFX.DrawString(Text, Font, New SolidBrush(ForeColor), New Rectangle(10, 21, Width - 17, Height - 5))
  2016.             End If
  2017.  
  2018.             CloseCoordinates = New Point(Width - 26, 4)
  2019.  
  2020.             If _ShowCloseButton = True Then
  2021.                 ' Draw the close button
  2022.                GFX.DrawString("r", New Font("Marlett", 7, FontStyle.Regular), New SolidBrush(Color.FromArgb(130, 130, 130)), New Rectangle(Width - 20, 10, Width, Height), New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near})
  2023.             End If
  2024.  
  2025.             CrvBorderPath.Dispose()
  2026.         End Sub
  2027.     End Class
  2028.  
  2029. #End Region
  2030.  
  2031. End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement