首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

纯代码绘制漂亮特效动画按钮,该怎么处理

2012-03-09 
纯代码绘制漂亮特效动画按钮VB.NET codeImports System.ComponentModelDefaultEvent(Click) _Public C

纯代码绘制漂亮特效动画按钮


VB.NET code
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                Gp.AddArc(New Rectangle(0, 0, Rounded, Rounded), 180, 90)                Gp.AddArc(New Rectangle(WW - Rounded, 0, Rounded, Rounded), -90, 90)                Gp.AddArc(New Rectangle(WW - Rounded, HH - Rounded, Rounded, Rounded), 0, 90)                Gp.AddArc(New Rectangle(0, HH - Rounded, Rounded, Rounded), 90, 90)                Gp.AddLine(New Point(0, HH - Rounded), New Point(0, Rounded / 2))                Using Lg As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, HH), ControlPaint.Dark(ButtonColor, 0.5), ButtonColor)                    G.FillPath(Lg, Gp)                    G.DrawPath(Pens.Black, Gp)                End Using            End Using            WW = WW - 3            HH = HH - 3            Using Gp As New Drawing2D.GraphicsPath                Gp.AddArc(New Rectangle(3, 3, Rounded, Rounded), 180, 90)                Gp.AddArc(New Rectangle(WW - Rounded, 3, Rounded, Rounded), -90, 90)                Gp.AddArc(New Rectangle(WW - Rounded, HH / 2 - Rounded - 1, Rounded, Rounded), 0, 90)                Gp.AddArc(New Rectangle(3, HH / 2 - Rounded - 1, Rounded, Rounded), 90, 90)                Using Lg As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, HH / 2), Color.FromArgb(220, 255, 255, 255), Color.FromArgb(50, 255, 255, 255))                    G.FillPath(Lg, Gp)                End Using            End Using            Using Gp As New Drawing2D.GraphicsPath                Gp.AddEllipse(New Rectangle(3, HH / 2 + 10, WW, HH / 2))                Using Lg As New Drawing2D.PathGradientBrush(Gp)                    Lg.CenterColor = Color.FromArgb(150, 255, 255, 255)                    Lg.SurroundColors = New Color() {Color.Transparent}                    Gp.FillMode = Drawing2D.FillMode.Winding                    G.FillPath(Lg, Gp)                End Using            End Using            Try                If _Text.Length <> 0 Then G.DrawString(_Text, Me.Font, New SolidBrush(TextColor), New Rectangle(0, 0, Me.Width, Me.Height), SF)            Catch            End Try        End Using    End Sub    Private Sub DSButton_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick    End Sub    Private Sub DSButton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown        If e.Button = MouseButtons.Left Then            MakeRoundedRect(RoundRectValue, Me, Color.Black)        End If    End Sub    Private Sub DSButton_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter        If DesignMode = False Then            IsMouseEnter = True            Timer1.Enabled = True        End If    End Sub    Private Sub DSButton_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave        If DesignMode = False Then            IsMouseEnter = False            Timer1.Enabled = True        End If    End Sub    Private Sub DSButton_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp        MakeRoundedRect(RoundRectValue, Me, _ButtonColor)    End Sub    Private Sub DSButton_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged        If Me.IsHandleCreated Then            MakeRoundedRect(RoundRectValue, Me, ButtonColor)        End If    End Sub    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick        Select Case IsMouseEnter            Case True                If IsShowAnimate = True Then                    nIndex = IIf(nIndex + 30 >= 225, 255, nIndex + 30)                    If nIndex >= 255 Then Timer1.Enabled = False                Else                    nIndex = 255                    Timer1.Enabled = False                End If            Case False                nIndex = IIf(nIndex - 20 <= 50, 50, nIndex - 20)                If nIndex <= 50 Then Timer1.Enabled = False        End Select        Try            MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * nIndex, ButtonColor.G / 255 * nIndex, ButtonColor.B / 255 * nIndex))        Catch        End Try    End SubEnd Class 


源码下载


[解决办法]
dylike又发新作品了,不错,版主推荐下.

以前那个label做的也很好,不错加油.
[解决办法]
咱vb.net出好帖子不容易。dylike加油。忙里偷闲啊。
[解决办法]
不错不错。
[解决办法]
感觉不错,顶个
[解决办法]
dylike又发新作品了,不错,版主推荐下
[解决办法]
犀利,犀利
[解决办法]
C# code
强大
[解决办法]
有点击效果吗?

[解决办法]
我想知道怎么用c画
谢谢
[解决办法]
下载了源码,我装的vs2008,为什么打不开啊?
[解决办法]
谢谢楼主
[解决办法]
好历害哦~~~~~~支持一下
[解决办法]
sheep 学习了 正在复习中
[解决办法]
不错不错。
[解决办法]
不错啊!!
[解决办法]
眼花缭乱
[解决办法]

[解决办法]
颜色搭配的稍微有点另类,否则更让人耳目一新。
[解决办法]
效果是相当不错。

[解决办法]
很好,很强大..

热点排行