Rechercher dans ce blog

mercredi 29 décembre 2021

GlowButtons

voici comment realiser un button glow.


vous pouvez choisir la couleur avec forecolor et GlowColor.

ma classe :

Public Class GlowButton : Inherits Button

    Private timer As New Timer With {.Enabled = 50}
    Private alpha As Integer = 0
    Private _GlowColor As Color
    Public Property GlowColor As Color
        Get
            Return _GlowColor
        End Get
        Set(value As Color)
            _GlowColor = value
            Me.invalidate()
        End Set
    End Property

    Public Sub New()
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
        AddHandler timer.Tick, New EventHandler(AddressOf timer_Tick)
        Me.FlatStyle = FlatStyle.Flat
        Me._GlowColor = Color.Blue
        Me.ForeColor = Color.Red
        Me.FlatAppearance.MouseDownBackColor = _GlowColor
    End Sub

    Private Sub timer_Tick(sender As Object, e As EventArgs)
        Dim increament As Integer = 25
        If alpha + increament < 255 Then
            alpha += increament
        Else
            timer.Stop()
            alpha = 255
        End If
        Me.FlatAppearance.MouseOverBackColor = _GlowColor
    End Sub

    Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
        MyBase.OnMouseEnter(e)
        Me.FlatAppearance.MouseOverBackColor = _GlowColor
        timer.Start()
    End Sub

    Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
        MyBase.OnMouseLeave(e)
        timer.Stop()
        alpha = 0
        Me.FlatAppearance.MouseOverBackColor = _GlowColor
    End Sub
End Class

Aucun commentaire:

Enregistrer un commentaire