2

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.

3 Answers 3

2

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.

2

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.

1
  • I tried that, but the image stretch functionality wasn't sufficient to handle what I wanted.
    – Jeff
    Jul 29, 2009 at 15:44
1

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
3
  • 1
    Actually found a much better solution--put the Insert in the MouseDown invent and the Raised int he MouseUp event--then it's tied to how long the mouse button is pressed down. (Just like real buttons works). This also prevents having a second click take place while the first simulated click is still running.
    – Jeff
    Jul 29, 2009 at 15:56
  • 1
    You didn't mention in the question that you're using Infragistics controls. Their WinButton doesn't do the image handling you're looking for‽ Jul 29, 2009 at 16:42
  • It does support images, but not the resizing capabilities I needed. (This particular application needed to be able to smoothly maximize on a wide range of screen resolutions)
    – Jeff
    Aug 25, 2009 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.