具有按下效果的按钮的代码?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

最新更新