Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Drawing.Drawing2D
- '<info>
- ' --------------------White Button--------------------
- ' Creator - SaketSaket (HF)
- ' UID - 1869668
- ' Inspiration & Credits to all Theme creators of HF
- ' Version - 1.0
- ' Date Created - 1st January 2015
- '
- '
- 'Special Thanks to Aeonhack for Basic RoundRect Functions...
- '
- '
- ' For bugs & Constructive Criticism contact me on HF
- ' If you like it & want to DONATE then pm me on HF
- ' --------------------White Button--------------------
- '<info>
- 'Please Leave Credits in Source, Do not redistribute
- Enum MouseState As Byte
- None = 0
- Over = 1
- Down = 2
- End Enum
- Module Draw
- 'Special Thanks to Aeonhack for RoundRect Functions... ;)
- Public Function RoundRect(ByVal rectangle As Rectangle, ByVal curve As Integer) As GraphicsPath
- Dim p As GraphicsPath = New GraphicsPath()
- Dim arcRectangleWidth As Integer = curve * 2
- p.AddArc(New Rectangle(rectangle.X, rectangle.Y, arcRectangleWidth, arcRectangleWidth), -180, 90)
- p.AddArc(New Rectangle(rectangle.Width - arcRectangleWidth + rectangle.X, rectangle.Y, arcRectangleWidth, arcRectangleWidth), -90, 90)
- p.AddArc(New Rectangle(rectangle.Width - arcRectangleWidth + rectangle.X, rectangle.Height - arcRectangleWidth + rectangle.Y, arcRectangleWidth, arcRectangleWidth), 0, 90)
- p.AddArc(New Rectangle(rectangle.X, rectangle.Height - arcRectangleWidth + rectangle.Y, arcRectangleWidth, arcRectangleWidth), 90, 90)
- p.AddLine(New Point(rectangle.X, rectangle.Height - arcRectangleWidth + rectangle.Y), New Point(rectangle.X, curve + rectangle.Y))
- Return p
- End Function
- End Module
- Public Class WhiteButton : Inherits Control
- Dim _state As MouseState
- Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
- MyBase.OnMouseDown(e)
- _state = MouseState.Down
- Invalidate()
- End Sub
- Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
- MyBase.OnMouseUp(e)
- _state = MouseState.Over
- Invalidate()
- End Sub
- Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
- MyBase.OnMouseEnter(e)
- _state = MouseState.Over
- Invalidate()
- End Sub
- Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
- MyBase.OnMouseLeave(e)
- _state = MouseState.None
- Invalidate()
- End Sub
- Sub New()
- SetStyle(ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.SupportsTransparentBackColor, True)
- BackColor = Color.Transparent
- DoubleBuffered = True
- Size = New Size(160, 50)
- _state = MouseState.None
- End Sub
- Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
- Dim b As Bitmap = New Bitmap(Width, Height)
- Dim g As Graphics = Graphics.FromImage(b)
- Dim rect As Rectangle = New Rectangle(0, 0, Width - 1, Height - 1)
- Dim innerrect As Rectangle = New Rectangle(3, 3, Width - 7, Height - 7)
- MyBase.OnPaint(e)
- g.SmoothingMode = SmoothingMode.HighQuality
- g.InterpolationMode = InterpolationMode.HighQualityBicubic
- g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
- g.Clear(BackColor)
- Dim buttonrect As New LinearGradientBrush(rect, Color.FromArgb(255, 255, 255), Color.FromArgb(219, 219, 219), LinearGradientMode.Vertical)
- g.FillPath(New SolidBrush(Color.FromArgb(228, 228, 228)), RoundRect(rect, 3))
- g.FillPath(buttonrect, RoundRect(innerrect, 3))
- Select Case _state
- Case MouseState.None
- Dim buttonrectnone As New LinearGradientBrush(rect, Color.FromArgb(255, 255, 255), Color.FromArgb(219, 219, 219), LinearGradientMode.Vertical)
- g.FillPath(New SolidBrush(Color.FromArgb(228, 228, 228)), RoundRect(rect, 3))
- g.FillPath(buttonrectnone, RoundRect(innerrect, 3))
- g.DrawPath(New Pen(Color.FromArgb(160, 160, 160)), RoundRect(innerrect, 3))
- g.DrawString(Text, New Font("Segoe UI", 10, FontStyle.Bold), Brushes.Black, innerrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
- Case MouseState.Down
- g.TranslateTransform(1, 1)
- g.DrawString(Text, New Font("Segoe UI", 10, FontStyle.Bold), Brushes.Black, innerrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
- Case MouseState.Over
- Dim buttonrectover As New LinearGradientBrush(innerrect, Color.FromArgb(219, 219, 219), Color.FromArgb(255, 255, 255), LinearGradientMode.Vertical)
- g.FillPath(New SolidBrush(Color.FromArgb(228, 228, 228)), RoundRect(rect, 3))
- g.FillPath(buttonrectover, RoundRect(innerrect, 3))
- g.DrawPath(New Pen(Color.FromArgb(160, 160, 160)), RoundRect(innerrect, 3))
- g.DrawString(Text, New Font("Segoe UI", 10, FontStyle.Bold), Brushes.Black, innerrect, New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
- End Select
- e.Graphics.DrawImage(b, New Point(0, 0))
- g.Dispose() : b.Dispose()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment