SaketSaket

SimpleMaterial Theme

Jul 25th, 2014
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 31.79 KB | None | 0 0
  1. Option Strict On
  2.  
  3. Imports System.Drawing.Drawing2D
  4.  
  5. 'Please Leave Credits in Source, Do not redistribute
  6.  
  7. '<info>
  8. ' -----------------Simple_Material Theme-----------------
  9. ' Creator - SaketSaket (HF)
  10. ' UID - 1869668
  11. ' Inspiration & Credits to all Theme creaters of HF
  12. ' Version - 1.0
  13. ' Date Created - 24th July 2014
  14. ' Date Modified - 25th July 2014
  15. '
  16. ' For bugs & Constructive Criticism contact me on HF
  17. ' If you like it & want to donate then pm me on HF
  18. ' -----------------Simple_Material Theme-----------------
  19. '<info>
  20.  
  21. 'Please Leave Credits in Source, Do not redistribute
  22.  
  23. Enum MouseState As Byte
  24.     None = 0
  25.     Over = 1
  26.     Down = 2
  27. End Enum
  28.  
  29. Module Draw
  30.     'Special Thanks to Aeonhack for RoundRect Functins... ;)
  31.     Public Function RoundRect(ByVal rectangle As Rectangle, ByVal curve As Integer) As GraphicsPath
  32.         Dim p As GraphicsPath = New GraphicsPath()
  33.         Dim arcRectangleWidth As Integer = curve * 2
  34.         p.AddArc(New Rectangle(rectangle.X, rectangle.Y, arcRectangleWidth, arcRectangleWidth), -180, 90)
  35.         p.AddArc(New Rectangle(rectangle.Width - arcRectangleWidth + rectangle.X, rectangle.Y, arcRectangleWidth, arcRectangleWidth), -90, 90)
  36.         p.AddArc(New Rectangle(rectangle.Width - arcRectangleWidth + rectangle.X, rectangle.Height - arcRectangleWidth + rectangle.Y, arcRectangleWidth, arcRectangleWidth), 0, 90)
  37.         p.AddArc(New Rectangle(rectangle.X, rectangle.Height - arcRectangleWidth + rectangle.Y, arcRectangleWidth, arcRectangleWidth), 90, 90)
  38.         p.AddLine(New Point(rectangle.X, rectangle.Height - arcRectangleWidth + rectangle.Y), New Point(rectangle.X, curve + rectangle.Y))
  39.         Return p
  40.     End Function
  41.     Public Function RoundRect(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal curve As Integer) As GraphicsPath
  42.         Dim rectangle As Rectangle = New Rectangle(x, y, width, height)
  43.         Dim p As GraphicsPath = New GraphicsPath()
  44.         Dim arcRectangleWidth As Integer = curve * 2
  45.         p.AddArc(New Rectangle(rectangle.X, rectangle.Y, arcRectangleWidth, arcRectangleWidth), -180, 90)
  46.         p.AddArc(New Rectangle(rectangle.Width - arcRectangleWidth + rectangle.X, rectangle.Y, arcRectangleWidth, arcRectangleWidth), -90, 90)
  47.         p.AddArc(New Rectangle(rectangle.Width - arcRectangleWidth + rectangle.X, rectangle.Height - arcRectangleWidth + rectangle.Y, arcRectangleWidth, arcRectangleWidth), 0, 90)
  48.         p.AddArc(New Rectangle(rectangle.X, rectangle.Height - arcRectangleWidth + rectangle.Y, arcRectangleWidth, arcRectangleWidth), 90, 90)
  49.         p.AddLine(New Point(rectangle.X, rectangle.Height - arcRectangleWidth + rectangle.Y), New Point(rectangle.X, curve + rectangle.Y))
  50.         Return p
  51.     End Function
  52. End Module
  53.  
  54. Public Class SimpleMaterialTheme : Inherits ContainerControl
  55.  
  56.     Sub New()
  57.         MyBase.New()
  58.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
  59.         DoubleBuffered = True
  60.         Dock = DockStyle.Fill
  61.     End Sub
  62.  
  63.     Protected Overrides Sub OnCreateControl()
  64.         MyBase.OnCreateControl()
  65.         ParentForm.FormBorderStyle = FormBorderStyle.None
  66.         If ParentForm.FindForm.TransparencyKey = Nothing Then ParentForm.FindForm.TransparencyKey = Color.Fuchsia
  67.     End Sub
  68.  
  69.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  70.         Dim b As Bitmap = New Bitmap(Width, Height)
  71.         Dim g As Graphics = Graphics.FromImage(b)
  72.         Dim rect As Rectangle = New Rectangle(0, 0, Width - 1, Height - 1)
  73.         MyBase.OnPaint(e)
  74.         g.SmoothingMode = SmoothingMode.HighQuality
  75.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  76.  
  77.         g.FillRectangle(New SolidBrush(Color.FromArgb(3, 169, 245)), rect)
  78.         e.Graphics.DrawImage(b, New Point(0, 0))
  79.         g.Dispose() : b.Dispose()
  80.     End Sub
  81. End Class
  82.  
  83. Public Class SimpleMaterialControlBox : Inherits Control
  84.  
  85.     Dim _state As MouseState = MouseState.None
  86.     Dim _x As Integer
  87.     ReadOnly _minrect As New Rectangle(5, 2, 30, 20)
  88.     ReadOnly _maxrect As New Rectangle(38, 2, 30, 20)
  89.     ReadOnly _closerect As New Rectangle(71, 2, 30, 20)
  90.  
  91.     Protected Overrides Sub OnMouseDown(ByVal e As Windows.Forms.MouseEventArgs)
  92.         MyBase.OnMouseDown(e)
  93.         If _x > 5 AndAlso _x < 35 Then
  94.             FindForm.WindowState = FormWindowState.Minimized
  95.         ElseIf _x > 38 AndAlso _x < 68 Then
  96.             If FindForm.WindowState = FormWindowState.Maximized Then
  97.                 FindForm.WindowState = FormWindowState.Minimized
  98.                 FindForm.WindowState = FormWindowState.Normal
  99.             Else
  100.                 FindForm.WindowState = FormWindowState.Minimized
  101.                 FindForm.WindowState = FormWindowState.Maximized
  102.             End If
  103.  
  104.         ElseIf _x > 71 AndAlso _x < 101 Then
  105.             FindForm.Close()
  106.         End If
  107.         _state = MouseState.Down : Invalidate()
  108.     End Sub
  109.  
  110.     Protected Overrides Sub OnMouseUp(ByVal e As Windows.Forms.MouseEventArgs)
  111.         MyBase.OnMouseUp(e)
  112.         _state = MouseState.Over : Invalidate()
  113.     End Sub
  114.  
  115.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  116.         MyBase.OnMouseEnter(e)
  117.         _state = MouseState.Over : Invalidate()
  118.     End Sub
  119.  
  120.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  121.         MyBase.OnMouseLeave(e)
  122.         _state = MouseState.None : Invalidate()
  123.     End Sub
  124.  
  125.     Protected Overrides Sub OnMouseMove(ByVal e As Windows.Forms.MouseEventArgs)
  126.         MyBase.OnMouseMove(e)
  127.         _x = e.Location.X
  128.         Invalidate()
  129.     End Sub
  130.  
  131.     Sub New()
  132.         MyBase.New()
  133.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.SupportsTransparentBackColor, True)
  134.         BackColor = Color.Transparent
  135.         DoubleBuffered = True
  136.         Width = 105
  137.         Height = 25
  138.         Anchor = AnchorStyles.Top Or AnchorStyles.Right
  139.     End Sub
  140.  
  141.     Protected Overrides Sub OnResize(ByVal e As EventArgs)
  142.         MyBase.OnResize(e)
  143.         Size = New Size(105, 25)
  144.     End Sub
  145.  
  146.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  147.         Dim b As Bitmap = New Bitmap(Width, Height)
  148.         Dim g As Graphics = Graphics.FromImage(b)
  149.         MyBase.OnPaint(e)
  150.         g.SmoothingMode = SmoothingMode.HighQuality
  151.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  152.  
  153.         Select Case _state
  154.             Case MouseState.None
  155.                 g.FillRectangle(New SolidBrush(Color.FromArgb(3, 169, 245)), _minrect)
  156.                 g.FillRectangle(New SolidBrush(Color.FromArgb(3, 169, 245)), _maxrect)
  157.                 g.FillRectangle(New SolidBrush(Color.FromArgb(3, 169, 245)), _closerect)
  158.                 g.DrawString("0", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _minrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  159.                 If FindForm.WindowState = FormWindowState.Maximized Then
  160.                     g.DrawString("2", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _maxrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  161.                 Else
  162.                     g.DrawString("1", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _maxrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  163.                 End If
  164.                 g.DrawString("r", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _closerect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  165.  
  166.             Case MouseState.Over
  167.                 If _x > 5 AndAlso _x < 35 Then
  168.                     g.FillRectangle(New SolidBrush(Color.FromArgb(3, 144, 208)), _minrect)
  169.                     g.DrawString("0", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _minrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  170.                     If FindForm.WindowState = FormWindowState.Maximized Then
  171.                         g.DrawString("2", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _maxrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  172.                     Else
  173.                         g.DrawString("1", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _maxrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  174.                     End If
  175.                     g.DrawString("r", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _closerect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  176.                 ElseIf _x > 38 AndAlso _x < 68 Then
  177.                     g.FillRectangle(New SolidBrush(Color.FromArgb(3, 144, 208)), _maxrect)
  178.                     g.DrawString("0", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _minrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  179.                     If FindForm.WindowState = FormWindowState.Maximized Then
  180.                         g.DrawString("2", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _maxrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  181.                     Else
  182.                         g.DrawString("1", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _maxrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  183.                     End If
  184.                     g.DrawString("r", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _closerect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  185.                 ElseIf _x > 71 AndAlso _x < 101 Then
  186.                     g.FillRectangle(New SolidBrush(Color.FromArgb(3, 144, 208)), _closerect)
  187.                     g.DrawString("0", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _minrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  188.                     If FindForm.WindowState = FormWindowState.Maximized Then
  189.                         g.DrawString("2", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _maxrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  190.                     Else
  191.                         g.DrawString("1", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _maxrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  192.                     End If
  193.                     g.DrawString("r", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _closerect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  194.                 End If
  195.             Case Else
  196.                 g.FillRectangle(New SolidBrush(Color.FromArgb(3, 169, 245)), _minrect)
  197.                 g.FillRectangle(New SolidBrush(Color.FromArgb(3, 169, 245)), _maxrect)
  198.                 g.FillRectangle(New SolidBrush(Color.FromArgb(3, 169, 245)), _closerect)
  199.                 g.DrawString("0", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _minrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  200.                 If FindForm.WindowState = FormWindowState.Maximized Then
  201.                     g.DrawString("2", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _maxrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  202.                 Else
  203.                     g.DrawString("1", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _maxrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  204.                 End If
  205.                 g.DrawString("r", New Font("Marlett", 12.5), New SolidBrush(Color.FromArgb(254, 254, 254)), _closerect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  206.  
  207.         End Select
  208.  
  209.         e.Graphics.DrawImage(b, New Point(0, 0))
  210.         g.Dispose() : b.Dispose()
  211.     End Sub
  212. End Class
  213.  
  214. Public Class SimpleMaterialRadioButton : Inherits Control
  215.     Private _check As Boolean
  216.  
  217.     Public Property Checked As Boolean
  218.         Get
  219.             Return _check
  220.         End Get
  221.         Set(value As Boolean)
  222.             _check = value
  223.             Invalidate()
  224.         End Set
  225.     End Property
  226.  
  227.     Sub New()
  228.         MyBase.New()
  229.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.SupportsTransparentBackColor, True)
  230.         BackColor = Color.Transparent
  231.         Size = New Size(200, 25)
  232.     End Sub
  233.  
  234.     Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
  235.         MyBase.OnTextChanged(e)
  236.         Invalidate()
  237.     End Sub
  238.  
  239.     Protected Overrides Sub OnClick(ByVal e As EventArgs)
  240.         MyBase.OnClick(e)
  241.         If Not Checked Then Checked = True
  242.         For Each ctrl As Control In Parent.Controls
  243.             If TypeOf ctrl Is SimpleMaterialRadioButton Then
  244.                 If ctrl.Handle = Handle Then Continue For
  245.                 If ctrl.Enabled Then DirectCast(ctrl, SimpleMaterialRadioButton).Checked = False
  246.             End If
  247.         Next
  248.     End Sub
  249.  
  250.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  251.         Dim b As Bitmap = New Bitmap(Width, Height)
  252.         Dim g As Graphics = Graphics.FromImage(b)
  253.         'Dim rect As Rectangle = New Rectangle(0, 0, Width - 1, Height - 1)
  254.         MyBase.OnPaint(e)
  255.         g.SmoothingMode = SmoothingMode.HighQuality
  256.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  257.         g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
  258.  
  259.         'g.FillRectangle(New SolidBrush(Color.FromArgb(255, 255, 255)), rect)
  260.         g.DrawString(Text, New Font("Tahoma", 10, FontStyle.Regular), New SolidBrush(Color.FromArgb(0, 0, 0)), New Rectangle(12, 4, Width, 16), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  261.  
  262.         Dim selectionrect As Rectangle = New Rectangle(3, 3, 17, 17)
  263.         Dim innerselectionrect As Rectangle = New Rectangle(7, 7, 9, 9)
  264.         g.DrawEllipse(New Pen(Color.FromArgb(109, 109, 109), 2), selectionrect)
  265.  
  266.         If Checked Then
  267.             g.DrawEllipse(New Pen(Color.FromArgb(76, 175, 80), 2), selectionrect)
  268.             g.FillEllipse(New SolidBrush(Color.FromArgb(76, 175, 80)), innerselectionrect)
  269.         Else
  270.             g.DrawEllipse(New Pen(Color.FromArgb(109, 109, 109)), selectionrect)
  271.         End If
  272.  
  273.         e.Graphics.DrawImage(b, New Point(0, 0))
  274.         g.Dispose() : b.Dispose()
  275.     End Sub
  276. End Class
  277.  
  278. Public Class SimpleMaterialCheckBox : Inherits Control
  279.     Private _check As Boolean
  280.  
  281.     Public Property Checked As Boolean
  282.         Get
  283.             Return _check
  284.         End Get
  285.         Set(value As Boolean)
  286.             _check = value
  287.             Invalidate()
  288.         End Set
  289.     End Property
  290.  
  291.     Sub New()
  292.         MyBase.New()
  293.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.SupportsTransparentBackColor, True)
  294.         BackColor = Color.Transparent
  295.         Size = New Size(200, 25)
  296.     End Sub
  297.  
  298.     Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
  299.         MyBase.OnTextChanged(e)
  300.         Invalidate()
  301.     End Sub
  302.  
  303.     Protected Overrides Sub OnClick(ByVal e As EventArgs)
  304.         MyBase.OnClick(e)
  305.         If Not Checked Then Checked = True Else Checked = False
  306.     End Sub
  307.  
  308.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  309.         Dim b As Bitmap = New Bitmap(Width, Height)
  310.         Dim g As Graphics = Graphics.FromImage(b)
  311.         'Dim rect As Rectangle = New Rectangle(0, 0, Width - 1, Height - 1)
  312.         MyBase.OnPaint(e)
  313.         g.SmoothingMode = SmoothingMode.HighQuality
  314.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  315.         g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
  316.  
  317.         'g.FillRectangle(New SolidBrush(Color.FromArgb(255, 255, 255)), rect)
  318.         g.DrawString(Text, New Font("Tahoma", 10, FontStyle.Regular), New SolidBrush(Color.FromArgb(0, 0, 0)), New Rectangle(12, 4, Width, 16), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  319.  
  320.         Dim selectionrect As Rectangle = New Rectangle(3, 3, 17, 17)
  321.         Dim innerselectionrect As Rectangle = New Rectangle(6, 6, 15, 15)
  322.  
  323.         If Checked Then
  324.             g.FillRectangle(New SolidBrush(Color.FromArgb(76, 175, 80)), selectionrect)
  325.             g.DrawString("b", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(255, 255, 255)), innerselectionrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  326.         Else
  327.             g.DrawRectangle(New Pen(Color.FromArgb(109, 109, 109), 2), selectionrect)
  328.         End If
  329.  
  330.         e.Graphics.DrawImage(b, New Point(0, 0))
  331.         g.Dispose() : b.Dispose()
  332.     End Sub
  333. End Class
  334.  
  335. Public Class SimpleMaterialProgressBar : Inherits Control
  336.     Private _val As Integer
  337.     Public Property Value() As Integer
  338.         Get
  339.             Return _val
  340.         End Get
  341.         Set(ByVal v As Integer)
  342.             If v > _max Then
  343.                 _val = _max
  344.             ElseIf v < 0 Then
  345.                 _val = 0
  346.             Else
  347.                 _val = v
  348.             End If
  349.             Invalidate()
  350.         End Set
  351.     End Property
  352.  
  353.     Private _max As Integer
  354.     Public Property Maximum() As Integer
  355.         Get
  356.             Return _max
  357.         End Get
  358.         Set(ByVal v As Integer)
  359.             If v < 1 Then
  360.                 _max = 1
  361.             Else
  362.                 _max = v
  363.             End If
  364.             If v < _val Then
  365.                 _val = _max
  366.             End If
  367.             Invalidate()
  368.         End Set
  369.     End Property
  370.  
  371.     Private _showPercentage As Boolean = False
  372.     Public Property ShowPercentage() As Boolean
  373.         Get
  374.             Return _ShowPercentage
  375.         End Get
  376.         Set(ByVal v As Boolean)
  377.             _ShowPercentage = v
  378.             Invalidate()
  379.         End Set
  380.     End Property
  381.  
  382.     Sub New()
  383.         MyBase.New()
  384.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.SupportsTransparentBackColor, True)
  385.         DoubleBuffered = True
  386.         BackColor = Color.Transparent
  387.         Size = New Size(300, 20)
  388.         _max = 100
  389.  
  390.     End Sub
  391.  
  392.     Protected Overrides Sub OnPaint(e As Windows.Forms.PaintEventArgs)
  393.         MyBase.OnPaint(e)
  394.         Dim g As Graphics = e.Graphics
  395.         g.SmoothingMode = SmoothingMode.HighQuality
  396.         g.FillRectangle(New SolidBrush(Color.FromArgb(180, 205, 241)), New Rectangle(0, 0, Width - 1, Height - 1))
  397.         Dim percent As Integer = CInt((Width - 1) * (_val / _max))
  398.         g.FillRectangle(New SolidBrush(Color.FromArgb(70, 137, 241)), New Rectangle(0, 0, percent, Height - 1))
  399.         If _showPercentage Then
  400.             g.DrawString(String.Format("{0}%", _val), New Font("Tahoma", 9, FontStyle.Bold), Brushes.White, New Rectangle(10, 1, Width - 1, Height - 1), New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  401.         End If
  402.     End Sub
  403. End Class
  404.  
  405. Public Class SimpleMaterialPanel : Inherits ContainerControl
  406.     Protected Overrides Sub OnResize(ByVal e As EventArgs)
  407.         MyBase.OnResize(e)
  408.         Invalidate()
  409.     End Sub
  410.  
  411.     Sub New()
  412.         MyBase.New()
  413.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
  414.         Size = New Size(240, 160)
  415.     End Sub
  416.  
  417.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  418.         Dim b As Bitmap = New Bitmap(Width, Height)
  419.         Dim g As Graphics = Graphics.FromImage(b)
  420.         Dim rect As Rectangle = New Rectangle(0, 0, Width - 1, Height - 1)
  421.         MyBase.OnPaint(e)
  422.         g.SmoothingMode = SmoothingMode.HighQuality
  423.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  424.  
  425.         g.FillRectangle(New SolidBrush(Color.FromArgb(255, 255, 255)), rect)
  426.         g.DrawRectangle(New Pen(Color.FromArgb(208, 208, 208), 2), rect)
  427.  
  428.         e.Graphics.DrawImage(b, New Point(0, 0))
  429.         g.Dispose() : b.Dispose()
  430.     End Sub
  431. End Class
  432.  
  433. Public Class SimpleMaterialWhiteButton : Inherits Control
  434.     Dim _state As MouseState
  435.  
  436.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  437.         MyBase.OnMouseDown(e)
  438.         _state = MouseState.Down
  439.         Invalidate()
  440.     End Sub
  441.  
  442.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  443.         MyBase.OnMouseUp(e)
  444.         _state = MouseState.Over
  445.         Invalidate()
  446.     End Sub
  447.  
  448.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  449.         MyBase.OnMouseEnter(e)
  450.         _state = MouseState.Over
  451.         Invalidate()
  452.     End Sub
  453.  
  454.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  455.         MyBase.OnMouseLeave(e)
  456.         _state = MouseState.None
  457.         Invalidate()
  458.     End Sub
  459.  
  460.     Sub New()
  461.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.SupportsTransparentBackColor, True)
  462.         BackColor = Color.Transparent
  463.         DoubleBuffered = True
  464.         Size = New Size(150, 30)
  465.         _state = MouseState.None
  466.     End Sub
  467.  
  468.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  469.         Dim b As Bitmap = New Bitmap(Width, Height)
  470.         Dim g As Graphics = Graphics.FromImage(b)
  471.         Dim rect As Rectangle = New Rectangle(0, 0, Width - 1, Height - 1)
  472.         MyBase.OnPaint(e)
  473.         g.SmoothingMode = SmoothingMode.HighQuality
  474.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  475.         g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
  476.         g.Clear(BackColor)
  477.         g.FillPath(New SolidBrush(Color.FromArgb(243, 243, 243)), RoundRect(rect, 2))
  478.         Dim btnfont As New Font("Tahoma", 10, FontStyle.Bold)
  479.         Select Case _state
  480.             Case MouseState.None
  481.                 g.DrawString(Text, btnfont, Brushes.Black, New Rectangle(0, 0, Width - 1, Height - 1), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  482.             Case MouseState.Down
  483.                 g.DrawPath(New Pen(Color.Black), RoundRect(New Rectangle(0, 0, Width - 1, Height - 1), 3))
  484.                 g.DrawString(Text, btnfont, Brushes.LightSlateGray, New Rectangle(0, 0, Width - 1, Height - 1), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  485.             Case MouseState.Over
  486.                 g.DrawPath(New Pen(Color.Black), RoundRect(New Rectangle(0, 0, Width - 1, Height - 1), 3))
  487.                 g.DrawString(Text, btnfont, New SolidBrush(Color.FromArgb(70, 137, 241)), New Rectangle(0, 0, Width - 1, Height - 1), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  488.         End Select
  489.         e.Graphics.DrawImage(b, New Point(0, 0))
  490.         g.Dispose() : b.Dispose()
  491.     End Sub
  492. End Class
  493.  
  494. Public Class SimpleMaterialBlueButton : Inherits Control
  495.     Dim _state As MouseState
  496.  
  497.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  498.         MyBase.OnMouseDown(e)
  499.         _state = MouseState.Down
  500.         Invalidate()
  501.     End Sub
  502.  
  503.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  504.         MyBase.OnMouseUp(e)
  505.         _state = MouseState.Over
  506.         Invalidate()
  507.     End Sub
  508.  
  509.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  510.         MyBase.OnMouseEnter(e)
  511.         _state = MouseState.Over
  512.         Invalidate()
  513.     End Sub
  514.  
  515.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  516.         MyBase.OnMouseLeave(e)
  517.         _state = MouseState.None
  518.         Invalidate()
  519.     End Sub
  520.  
  521.     Sub New()
  522.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.SupportsTransparentBackColor, True)
  523.         BackColor = Color.Transparent
  524.         DoubleBuffered = True
  525.         Size = New Size(150, 30)
  526.         _state = MouseState.None
  527.     End Sub
  528.  
  529.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  530.         Dim b As Bitmap = New Bitmap(Width, Height)
  531.         Dim g As Graphics = Graphics.FromImage(b)
  532.         Dim rect As Rectangle = New Rectangle(0, 0, Width - 1, Height - 1)
  533.         MyBase.OnPaint(e)
  534.         g.SmoothingMode = SmoothingMode.HighQuality
  535.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  536.         g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
  537.         g.Clear(BackColor)
  538.         g.FillPath(New SolidBrush(Color.FromArgb(3, 169, 245)), RoundRect(rect, 2))
  539.         Dim btnfont As New Font("Tahoma", 10, FontStyle.Bold)
  540.         Select Case _state
  541.             Case MouseState.None
  542.                 g.DrawString(Text, btnfont, Brushes.White, New Rectangle(0, 0, Width - 1, Height - 1), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  543.             Case MouseState.Down
  544.                 g.DrawPath(New Pen(Color.Black), RoundRect(New Rectangle(0, 0, Width - 1, Height - 1), 3))
  545.                 g.DrawString(Text, btnfont, Brushes.LightSlateGray, New Rectangle(0, 0, Width - 1, Height - 1), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  546.             Case MouseState.Over
  547.                 g.DrawPath(New Pen(Color.Black), RoundRect(New Rectangle(0, 0, Width - 1, Height - 1), 3))
  548.                 g.DrawString(Text, btnfont, New SolidBrush(Color.FromArgb(240, 240, 240)), New Rectangle(0, 0, Width - 1, Height - 1), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  549.         End Select
  550.         e.Graphics.DrawImage(b, New Point(0, 0))
  551.         g.Dispose() : b.Dispose()
  552.     End Sub
  553. End Class
  554.  
  555. Public Class SimpleMaterialTextBox : Inherits Control
  556.     Dim WithEvents _tb As New TextBox
  557.  
  558.     Private _allowpassword As Boolean = False
  559.     Public Shadows Property UseSystemPasswordChar() As Boolean
  560.         Get
  561.             Return _allowpassword
  562.         End Get
  563.         Set(ByVal v As Boolean)
  564.             _tb.UseSystemPasswordChar = UseSystemPasswordChar
  565.             _allowpassword = v
  566.             Invalidate()
  567.         End Set
  568.     End Property
  569.  
  570.     Private _maxChars As Integer = 32767
  571.     Public Shadows Property MaxLength() As Integer
  572.         Get
  573.             Return _maxChars
  574.         End Get
  575.         Set(ByVal v As Integer)
  576.             _maxChars = v
  577.             _tb.MaxLength = MaxLength
  578.             Invalidate()
  579.         End Set
  580.     End Property
  581.  
  582.     Private _textAlignment As HorizontalAlignment
  583.     Public Shadows Property TextAlign() As HorizontalAlignment
  584.         Get
  585.             Return _textAlignment
  586.         End Get
  587.         Set(ByVal v As HorizontalAlignment)
  588.             _textAlignment = v
  589.             Invalidate()
  590.         End Set
  591.     End Property
  592.  
  593.     Private _multiLine As Boolean = False
  594.     Public Shadows Property MultiLine() As Boolean
  595.         Get
  596.             Return _multiLine
  597.         End Get
  598.         Set(ByVal v As Boolean)
  599.             _multiLine = v
  600.             _tb.Multiline = v
  601.             OnResize(EventArgs.Empty)
  602.             Invalidate()
  603.         End Set
  604.     End Property
  605.  
  606.     Private _readOnly As Boolean = False
  607.     Public Shadows Property [ReadOnly]() As Boolean
  608.         Get
  609.             Return _readOnly
  610.         End Get
  611.         Set(ByVal v As Boolean)
  612.             _readOnly = v
  613.             If _tb IsNot Nothing Then
  614.                 _tb.ReadOnly = v
  615.             End If
  616.         End Set
  617.     End Property
  618.  
  619.     Protected Overrides Sub OnTextChanged(ByVal e As EventArgs)
  620.         MyBase.OnTextChanged(e)
  621.         Invalidate()
  622.     End Sub
  623.  
  624.     Protected Overrides Sub OnBackColorChanged(ByVal e As EventArgs)
  625.         MyBase.OnBackColorChanged(e)
  626.         Invalidate()
  627.     End Sub
  628.  
  629.     Protected Overrides Sub OnForeColorChanged(ByVal e As EventArgs)
  630.         MyBase.OnForeColorChanged(e)
  631.         _tb.ForeColor = ForeColor
  632.         Invalidate()
  633.     End Sub
  634.  
  635.     Protected Overrides Sub OnFontChanged(ByVal e As EventArgs)
  636.         MyBase.OnFontChanged(e)
  637.         _tb.Font = Font
  638.     End Sub
  639.  
  640.     Protected Overrides Sub OnGotFocus(ByVal e As EventArgs)
  641.         MyBase.OnGotFocus(e)
  642.         _tb.Focus()
  643.     End Sub
  644.  
  645.     Private Sub TextChangeTb() Handles _tb.TextChanged
  646.         Text = _tb.Text
  647.     End Sub
  648.  
  649.     Private Sub TextChng() Handles MyBase.TextChanged
  650.         _tb.Text = Text
  651.     End Sub
  652.  
  653.     Public Sub NewTextBox()
  654.         With _tb
  655.             .Text = String.Empty
  656.             .BackColor = Color.FromArgb(255, 255, 255)
  657.             .TextAlign = HorizontalAlignment.Center
  658.             .BorderStyle = BorderStyle.None
  659.             .Location = New Point(3, 3)
  660.             .Font = New Font("Tahoma", 10, FontStyle.Bold)
  661.             .Size = New Size(Width - 3, Height - 3)
  662.             .UseSystemPasswordChar = UseSystemPasswordChar
  663.         End With
  664.     End Sub
  665.  
  666.     Sub New()
  667.         MyBase.New()
  668.         NewTextBox()
  669.         Controls.Add(_tb)
  670.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.SupportsTransparentBackColor, True)
  671.         DoubleBuffered = True
  672.         BackColor = Color.Transparent
  673.         ForeColor = Color.Black
  674.         Font = New Font("Tahoma", 10, FontStyle.Bold)
  675.         Size = New Size(150, 30)
  676.     End Sub
  677.  
  678.     Protected Overrides Sub OnPaint(ByVal e As Windows.Forms.PaintEventArgs)
  679.         Dim b As Bitmap = New Bitmap(Width, Height)
  680.         Dim g As Graphics = Graphics.FromImage(b)
  681.         MyBase.OnPaint(e)
  682.         g.SmoothingMode = SmoothingMode.HighQuality
  683.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  684.         g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
  685.  
  686.         With _tb
  687.             .TextAlign = TextAlign
  688.             .UseSystemPasswordChar = UseSystemPasswordChar
  689.         End With
  690.         Dim rect As Rectangle = New Rectangle(0, 0, Width - 1, Height - 1)
  691.         g.FillPath(New SolidBrush(Color.FromArgb(255, 255, 255)), RoundRect(rect, 3))
  692.         g.DrawPath(New Pen(Color.Black), RoundRect(New Rectangle(0, 0, Width - 1, Height - 1), 3))
  693.         e.Graphics.DrawImage(b, New Point(0, 0))
  694.         g.Dispose() : b.Dispose()
  695.     End Sub
  696.  
  697.     Protected Overrides Sub OnResize(e As EventArgs)
  698.         MyBase.OnResize(e)
  699.         If Not MultiLine Then
  700.             Dim tbheight As Integer = _tb.Height
  701.             _tb.Location = New Point(10, CType(((Height / 2) - (tbheight / 2) - 1), Integer))
  702.             _tb.Size = New Size(Width - 20, tbheight)
  703.         Else
  704.             _tb.Location = New Point(10, 10)
  705.             _tb.Size = New Size(Width - 20, Height - 20)
  706.         End If
  707.     End Sub
  708. End Class
Advertisement
Add Comment
Please, Sign In to add comment