具有下推效果的按钮的代码? VB.net

问题描述

如何让按钮具有下推效果?我不是在谈论 FlatStyle popup。它必须“向下”,可以这么说,在第二次点击它时,它会在鼠标点击结束时“向上”。

这是我迄今为止尝试过的代码。你有更好的想法吗?

        Dim RememberXpos As Integer = Button1.Location.X
        Dim RememberYpos As Integer = Button1.Location.Y
        Dim ButtonXEnd As Integer = Button1.Location.X + Button1.Size.Width
        Dim ButtonYEnd As Integer = Button1.Location.Y + Button1.Size.Height
        Dim oldSize As Size = Button1.Size

        ' shrink
        Button1.Size = New Size(CInt(Button1.Size.Width * 0.9),CInt(Button1.Size.Height * 0.9))

        ' center the button
        Dim ButtonXEndeDiffHalf As Integer = CInt(Math.Round((ButtonXEnd - (Button1.Location.X + Button1.Size.Width)) / 2.0,0))
        Dim ButtonYEndeDiffHalf As Integer = CInt(Math.Round((ButtonYEnd - (Button1.Location.Y + Button1.Size.Height)) / 2.0,0))
        Button1.Location = New Point(Button1.Location.X + ButtonXEndeDiffHalf,Button1.Location.Y + ButtonYEndeDiffHalf)
        Button1.Update()
        System.Threading.Thread.Sleep(150)

        ' re-enlarge
        Button1.Size = oldSize
        Button1.Location = New Point(RememberXpos,RememberYpos)

解决方法

改用复选框并将外观设置为按钮。

CheckBox1.Appearance = Appearance.Button