Jeff
Jeff

Reputation: 8138

Simulate Winforms Button Click Animation

I have a button and inside my button I have an image control. When the users click on the image I'd like to animate the button so it appears the button was pressed. I don't really care whether the actual button press event fires or not--it's the illusion of a button press I want to see.

Note: the only options I see on the web involve writing directly to the Windows API--a level of complexity and non-upgradability I really don't want to get into.

Upvotes: 2

Views: 3381

Answers (3)

Jeff
Jeff

Reputation: 8138

I ended up making my picturbox look like a button by giving it a raised border style. Then on the mouseclick event I simulate the look of a button press by changing the border style for a few hundred miliseconds.

Private Sub simulateButtonPress(ByRef pictureBox As Infragistics.Win.UltraWinEditors.UltraPictureBox)
    pictureBox.BorderStyle = Infragistics.Win.UIElementBorderStyle.Inset
    Application.DoEvents()
    System.Threading.Thread.Sleep(400)
    pictureBox.BorderStyle = Infragistics.Win.UIElementBorderStyle.Raised
    Application.DoEvents()
End Sub

Upvotes: 1

CoderDennis
CoderDennis

Reputation: 13837

Why are you using an image control inside your button control instead of using the button control's Image property?

Using the Image property of the button will give you a button with an image that the user can press and that will raise the OnClick event without doing any extra work or re-implementing features that are already available.

Upvotes: 2

Kredns
Kredns

Reputation: 37201

Why not just use two different images, one for a normal state, and another for when your button is being pressed.

If you want to go for more complicated route try using GDI+. Here is a quick sample tutorial on how to do this.

Upvotes: 2

Related Questions