纯代码绘制漂亮特效动画按钮解决方案
纯代码绘制漂亮特效动画按钮

Imports System.ComponentModel
<DefaultEvent("Click")> _
Public Class DSButton
Private _ButtonColor As Color = Color.White
Private SF As New System.Drawing.StringFormat
Private _Text As String
<DefaultValue(True)>
Public Property ButtonColor As Color
Get
Return _ButtonColor
End Get
Set(ByVal value As Color)
_ButtonColor = value
MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * 50, ButtonColor.G / 255 * 50, ButtonColor.B / 255 * 50))
End Set
End Property
Public Property RoundRectValue As Integer = 10
Private nIndex As Integer = 0
Private IsMouseEnter As Boolean = False
Public Property IsShowAnimate As Boolean = False
Public Property ButtonText As String
Get
Return _Text
End Get
Set(ByVal value As String)
_Text = value
MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * 50, ButtonColor.G / 255 * 50, ButtonColor.B / 255 * 50))
End Set
End Property
Private _TextColor As Color = Color.White
Public Property TextColor As Color
Get
Return _TextColor
End Get
Set(ByVal value As Color)
_TextColor = value
MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * 50, ButtonColor.G / 255 * 50, ButtonColor.B / 255 * 50))
End Set
End Property
Private Sub DSButton_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetStyle(ControlStyles.UserPaint, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
SetStyle(ControlStyles.ResizeRedraw, True)
SetStyle(ControlStyles.Selectable, True)
SF.LineAlignment = StringAlignment.Center
SF.Alignment = StringAlignment.Center
MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * 50, ButtonColor.G / 255 * 50, ButtonColor.B / 255 * 50))
End Sub
Private Sub MakeRoundedRect(ByVal Rounded As Integer, ByVal Ct As Control, ByVal ButtonColor As Color)
If Ct.BackgroundImage IsNot Nothing Then Ct.BackgroundImage.Dispose()
Ct.BackgroundImage = New Bitmap(Ct.Width, Ct.Height)
Dim WW, HH As Integer
WW = Ct.Width - 1
HH = Ct.Height - 1
Using G As Graphics = Graphics.FromImage(Ct.BackgroundImage)
G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
G.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
Using Gp As New Drawing2D.GraphicsPath