Advertisement
SaketSaket

Simple_Material Theme Updated 1

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