使用 VB.NET 实现自定义特效动画按钮

Imports System.ComponentModel  _ 

Public Class DSButton
    Private _ButtonColor As Color = Color.White
    Private SF As New System.Drawing.StringFormat
    Private _Text As String

    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
    ' ... 其他代码 ...
End Class

这段代码展示了如何使用 VB.NET 创建一个自定义按钮类 DSButton,并实现了以下功能:

  • 自定义按钮颜色 (ButtonColor)
  • 圆角矩形按钮 (RoundRectValue)
  • 自定义按钮文本 (ButtonText)
  • 自定义文本颜色 (TextColor)

代码中使用了 MakeRoundedRect 函数来绘制圆角矩形按钮,并根据按钮颜色动态调整阴影效果。

rar
圆角矩形.rar 预估大小:60个文件
folder
圆角矩形 文件夹
file
圆角矩形.vbproj.user 143B
file
圆角矩形.vbproj 5KB
folder
My Project 文件夹
file
Settings.settings 279B
file
AssemblyInfo.vb 1KB
file
Settings.Designer.vb 3KB
file
Application.Designer.vb 1KB
file
Resources.resx 5KB
file
Resources.Designer.vb 3KB
file
Application.myapp 510B
file
Form1.resx 90KB
file
Form1.Designer.vb 16KB
file
DSButton.Designer.vb 2KB
file
DSButton.vb 7KB
file
Form1.vb 1KB
file
DSButton.resx 6KB
folder
obj 文件夹
folder
x86 文件夹
folder
Debug 文件夹
file
WindowsApplication1.exe 19KB
file
GenerateResource-ResGen.read.1.tlog 1KB
file
圆角矩形.vbproj.FileListAbsolute.txt 993B
file
圆角矩形.pdb 48KB
file
WindowsApplication1.pdb 34KB
folder
TempPE 文件夹
file
My Project.Resources.Designer.vb.dll 8KB
file
WindowsApplication1.DSButton.resources 180B
file
WindowsApplication1.vbproj.FileListAbsolute.txt 1KB
file
DesignTimeResolveAssemblyReferencesInput.cache 5KB
file
WindowsApplication1.Resources.resources 180B
file
DesignTimeResolveAssemblyReferences.cache 5KB
file
GenerateResource-ResGen.write.1.tlog 644B
file
圆角矩形.exe 91KB
file
WindowsApplication1.xml 708B
file
圆角矩形.xml 701B
file
WindowsApplication1.Form1.resources 57KB
folder
Release 文件夹
file
纯代码特效按钮.pdb 46KB
file
GenerateResource-ResGen.read.1.tlog 1KB
file
圆角矩形.vbproj.FileListAbsolute.txt 1KB
folder
TempPE 文件夹
file
My Project.Resources.Designer.vb.dll 8KB
file
WindowsApplication1.DSButton.resources 180B
file
DesignTimeResolveAssemblyReferencesInput.cache 5KB
file
纯代码特效按钮.xml 710B
file
WindowsApplication1.Resources.resources 180B
file
DesignTimeResolveAssemblyReferences.cache 5KB
file
纯代码特效按钮.exe 88KB
file
GenerateResource-ResGen.write.1.tlog 656B
file
WindowsApplication1.Form1.resources 57KB
folder
bin 文件夹
folder
Debug 文件夹
file
圆角矩形.vshost.exe 11KB
file
WindowsApplication1.exe 19KB
file
圆角矩形.pdb 48KB
file
WindowsApplication1.pdb 34KB
file
WindowsApplication1.vshost.exe.manifest 490B
file
WindowsApplication1.vshost.exe 11KB
file
WindowsApplication1.xml 708B
file
圆角矩形.xml 701B
folder
Release 文件夹
file
纯代码特效按钮.pdb 46KB
file
纯代码特效按钮.vshost.exe.manifest 490B
file
纯代码特效按钮.vshost.exe 11KB
file
圆角矩形.vshost.exe.manifest 490B
file
纯代码特效按钮.xml 710B
file
纯代码特效按钮.exe 88KB
file
纯代码绘制漂亮特效按钮.exe 91KB
file
圆角矩形.sln 878B
file
圆角矩形.suo 17KB
...
rar 文件大小:497.39KB