Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Data
Imports System.Windows.Forms
Imports System.ComponentModel.Design.Serialization
Namespace Usercontrols
Public Class gradiant_button
Inherits System.Windows.Forms.Button
Private _OutlineColor As Color = Color.White
Private _FillColor As Color = Color.Gray
Private _FillColor_Gradiant As Color = Color.SteelBlue
Private _FillColorDisabled As Color = Color.LightGray
Private _FillColorDisabled_Gradiant As Color = Color.Gray
Private _FillColorHover As Color = Color.Beige
Private _FillColorHover_Gradiant As Color = Color.Beige
Private _TextColor As Color = Color.Black
Private _TextColor_Gradiant As Color = Color.Black
Private SwapMouse As Boolean = False
Private DownMouse As Boolean = False
#Region "Coloring code & Properties"
Public Property FillColor() As Color
Get
Return _FillColor
End Get
Set(ByVal Value As Color)
_FillColor = Value
Invalidate()
End Set
End Property
Public Property FillColor_Gradiant() As Color
Get
Return _FillColor_Gradiant
End Get
Set(ByVal Value As Color)
_FillColor_Gradiant = Value
Invalidate()
End Set
End Property
Public Property FillColorDisabled() As Color
Get
Return _FillColorDisabled
End Get
Set(ByVal Value As Color)
_FillColorDisabled = Value
Invalidate()
End Set
End Property
Public Property FillColorDisabled_Gradiant() As Color
Get
Return _FillColorDisabled_Gradiant
End Get
Set(ByVal Value As Color)
_FillColorDisabled_Gradiant = Value
Invalidate()
End Set
End Property
Public Property FillColorHover() As Color
Get
Return _FillColorHover
End Get
Set(ByVal Value As Color)
_FillColorHover = Value
Invalidate()
End Set
End Property
Public Property FillColorHover_Gradiant() As Color
Get
Return _FillColorHover_Gradiant
End Get
Set(ByVal Value As Color)
_FillColorHover_Gradiant = Value
Invalidate()
End Set
End Property
Public Property TextColor() As Color
Get
Return _TextColor
End Get
Set(ByVal Value As Color)
_TextColor = Value
Invalidate()
End Set
End Property
Public Property TextColor_Gradiant() As Color
Get
Return _TextColor_Gradiant
End Get
Set(ByVal Value As Color)
_TextColor_Gradiant = Value
Invalidate()
End Set
End Property
#End Region
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
This call is required by the Windows Form Designer.
InitializeComponent()
Add any initialization after the InitializeComponent() call
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
SetStyle(ControlStyles.DoubleBuffer, True)
SetStyle(ControlStyles.ResizeRedraw, True)
End Sub
UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
NOTE: The following procedure is required by the Windows Form Designer
It can be modified using the Windows Form Designer.
Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
outline_button
Me.Name = "outline_button"
Me.Size = New System.Drawing.Size(62, 62)
End Sub
#End Region
#Region "Paint and Mouse"
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim GradiantBrush As Brush
Dim TextBrush As Brush
Dim HoverBrush As Brush
Dim DisabledBrush As Brush
Dim StringSize As New SizeF()
Setup gradiants into the brushes 3, Text, Hover, Normal
HoverBrush = New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, Me.Height), Me.FillColorHover, Me.FillColorHover_Gradiant)
GradiantBrush = New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, Me.Height), Me._FillColor, Me._FillColor_Gradiant)
TextBrush = New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, Me.Height), Me._TextColor, Me._TextColor_Gradiant)
DisabledBrush = New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, Me.Height), Me._FillColorDisabled, Me._FillColorDisabled_Gradiant)
if mouse hovering
If Me.Enabled Then
If Me.SwapMouse = True Then
e.Graphics.FillRectangle(HoverBrush, ClientRectangle)
Else
e.Graphics.FillRectangle(GradiantBrush, ClientRectangle)
End If
Else
e.Graphics.FillRectangle(DisabledBrush, ClientRectangle)
End If
if mouse button down change border style
If Me.DownMouse = True And Me.Enabled Then
ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Bump)
Else
ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Etched)
End If
text centred in button
StringSize = e.Graphics.MeasureString(Text, Font)
e.Graphics.DrawString(Text, Font, TextBrush, Convert.ToInt32(Width / 2) - Convert.ToInt32(StringSize.Width / 2), Convert.ToInt32(Height / 2) - Convert.ToInt32(StringSize.Height / 2))
End Sub
#Region "Mouse events"
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
Me.SwapMouse = False
Me.Refresh()
MyBase.OnMouseLeave(New EventArgs())
End Sub
Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
Me.SwapMouse = True
Me.Refresh()
MyBase.OnMouseEnter(New EventArgs())
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
Me.DownMouse = True
Me.Refresh()
MyBase.OnMouseDown(e)
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
Me.DownMouse = False
Me.Refresh()
MyBase.OnMouseUp(e)
End Sub
#End Region
#End Region
Protected Overrides Sub OnValidated(ByVal e As System.EventArgs)
Me.Refresh()
End Sub
End Class
End Namespace