Code for a button that has a push-down effect? Vb.net

Viewed 107

What can you do to make a button have a push-down effect? I'm not talking about FlatStyle popup. It has to go “down”, so to speak, in the second it is clicked and “come up” when the mouseclick is over.

This is the code I've tried so far. Do you have better ideas?

        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)
1 Answers

Use a Checkbox instead and set Appearance to Button.

CheckBox1.Appearance = Appearance.Button
Related