Visual Basic question.

Yes, I did try Googling before asking here.

If it makes any difference, I’m using the version that comes with Visual Studio 2010.

This should be easy I think. As you may already know, the PerformClick method raises a click event, but it doesn’t show the button pushing down and back up again. I’m sure there must be code to simulate a button being clicked by the mouse. If so, what is it?

Thanks.

It’s not that easy but this has what you want:

You need to use all of the code in JoeFox’s OP and then replace his Button1_Click code with .Paul.'s version. You will also need to change

Dim p As Point = Me.PointToScreen(New Point(653, 264))

to coordinates that suit your button.

I tried it and it does work, but it’s so fast it’s hard to see the mouse moving and the button being depressed.

This assumes you’re writing a Windows app - it won’t work with a web app.

Yeah, it’s a Windows and not a Web app. Anyway, I’ll check out the code. Thanks.

You can make a button looked like it is being pressed by sending it the BM_SETSTATE message. You send it twice: once with the wParam set to TRUE to make the button look pushed and again with the wParam set to FALSE to return it to normal. Pause for however long you want to in between.

I’m having a hard time finding an example of how to use it, and BM_SETSTATE and other variants don’t seem to apply to the latest version of VB.

I left out a lot of the details. You need to send BM_SETSTATE to the button using the SendMessage API. I’m not familiar with the latest VB stuff, but in the past you would declare a private function and declare a constant for the message you want to send. I believe that the window handle (hwnd) you need is a property of the button. So the code would look something like this (again, this is from my recollection of how VB worked in the past. It may differ somewhat now):

Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const BM_SETSTATE As Long = &H00F3

Call SendMessage(myButton.hwnd, BM_SETSTATE, 1, 0)

Something like that, anyway. I’m sure what I have above isn’t exactly right. You should be able to find many examples of people using SendMessage in the current version of VB to model your code from.

OK, I think I saw something like that. Thank you. I’ll give it a try.