SaketSaket

White Button

Feb 2nd, 2015
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.23 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2.  
  3. '<info>
  4. ' --------------------White Button--------------------
  5. ' Creator - SaketSaket (HF)
  6. ' UID - 1869668
  7. ' Inspiration & Credits to all Theme creators of HF
  8. ' Version - 1.0
  9. ' Date Created - 1st January 2015
  10. '
  11. '
  12. 'Special Thanks to Aeonhack for Basic RoundRect Functions...
  13. '
  14. '
  15. ' For bugs & Constructive Criticism contact me on HF
  16. ' If you like it & want to DONATE then pm me on HF
  17. ' --------------------White Button--------------------
  18. '<info>
  19.  
  20. 'Please Leave Credits in Source, Do not redistribute
  21.  
  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 Functions... ;)
  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. End Module
  42.  
  43. Public Class WhiteButton : Inherits Control
  44.     Dim _state As MouseState
  45.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  46.         MyBase.OnMouseDown(e)
  47.         _state = MouseState.Down
  48.         Invalidate()
  49.     End Sub
  50.  
  51.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  52.         MyBase.OnMouseUp(e)
  53.         _state = MouseState.Over
  54.         Invalidate()
  55.     End Sub
  56.  
  57.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  58.         MyBase.OnMouseEnter(e)
  59.         _state = MouseState.Over
  60.         Invalidate()
  61.     End Sub
  62.  
  63.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  64.         MyBase.OnMouseLeave(e)
  65.         _state = MouseState.None
  66.         Invalidate()
  67.     End Sub
  68.  
  69.     Sub New()
  70.         SetStyle(ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.SupportsTransparentBackColor, True)
  71.         BackColor = Color.Transparent
  72.         DoubleBuffered = True
  73.         Size = New Size(160, 50)
  74.         _state = MouseState.None
  75.     End Sub
  76.  
  77.     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  78.         Dim b As Bitmap = New Bitmap(Width, Height)
  79.         Dim g As Graphics = Graphics.FromImage(b)
  80.         Dim rect As Rectangle = New Rectangle(0, 0, Width - 1, Height - 1)
  81.         Dim innerrect As Rectangle = New Rectangle(3, 3, Width - 7, Height - 7)
  82.         MyBase.OnPaint(e)
  83.         g.SmoothingMode = SmoothingMode.HighQuality
  84.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  85.         g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
  86.         g.Clear(BackColor)
  87.         Dim buttonrect As New LinearGradientBrush(rect, Color.FromArgb(255, 255, 255), Color.FromArgb(219, 219, 219), LinearGradientMode.Vertical)
  88.         g.FillPath(New SolidBrush(Color.FromArgb(228, 228, 228)), RoundRect(rect, 3))
  89.         g.FillPath(buttonrect, RoundRect(innerrect, 3))
  90.         Select Case _state
  91.             Case MouseState.None
  92.                 Dim buttonrectnone As New LinearGradientBrush(rect, Color.FromArgb(255, 255, 255), Color.FromArgb(219, 219, 219), LinearGradientMode.Vertical)
  93.                 g.FillPath(New SolidBrush(Color.FromArgb(228, 228, 228)), RoundRect(rect, 3))
  94.                 g.FillPath(buttonrectnone, RoundRect(innerrect, 3))
  95.                 g.DrawPath(New Pen(Color.FromArgb(160, 160, 160)), RoundRect(innerrect, 3))
  96.                 g.DrawString(Text, New Font("Segoe UI", 10, FontStyle.Bold), Brushes.Black, innerrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  97.             Case MouseState.Down
  98.                 g.TranslateTransform(1, 1)
  99.                 g.DrawString(Text, New Font("Segoe UI", 10, FontStyle.Bold), Brushes.Black, innerrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  100.             Case MouseState.Over
  101.                 Dim buttonrectover As New LinearGradientBrush(innerrect, Color.FromArgb(219, 219, 219), Color.FromArgb(255, 255, 255), LinearGradientMode.Vertical)
  102.                 g.FillPath(New SolidBrush(Color.FromArgb(228, 228, 228)), RoundRect(rect, 3))
  103.                 g.FillPath(buttonrectover, RoundRect(innerrect, 3))
  104.                 g.DrawPath(New Pen(Color.FromArgb(160, 160, 160)), RoundRect(innerrect, 3))
  105.                 g.DrawString(Text, New Font("Segoe UI", 10, FontStyle.Bold), Brushes.Black, innerrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  106.         End Select
  107.         e.Graphics.DrawImage(b, New Point(0, 0))
  108.         g.Dispose() : b.Dispose()
  109.     End Sub
  110. End Class
Advertisement
Add Comment
Please, Sign In to add comment