Press a button programatically

  • Thread starter Thread starter joe
  • Start date Start date
J

joe

Hi,
Is there a way to push a button programatically (and for
that matter to emulate any other key/mouse event).
For example when a button is pressed by a mouse/key it
caves in and events get fired.
How do I cause this to happen programatically?
Something like:

MyButton.ClickIt()-and the button caves in

The Windows calculator does it nicely-copy some numbers in
the clipboard and paste them in the calculator and its
buttons get clicked.

Thanks
 
* "joe said:
Is there a way to push a button programatically (and for
that matter to emulate any other key/mouse event).
For example when a button is pressed by a mouse/key it
caves in and events get fired.
How do I cause this to happen programatically?
Something like:

MyButton.ClickIt()-and the button caves in

\\\
Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
) As Int32

Private Const BM_SETSTATE As Int32 = &HF3
Private Const BM_GETSTATE As Int32 = &HF2

Private m_blnDown As Boolean

..
..
..

Private Sub Timer1_Tick( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles Timer1.Tick
If m_blnDown Then
SendMessage(Me.Button1.Handle, BM_SETSTATE, 0, 0)
Else
SendMessage(Me.Button1.Handle, BM_SETSTATE, 1, 0)
End If
m_blnDown = Not m_blnDown
End Sub
///
 
Hello Herfried

Would Button1.PerformClick() do ?
rather simpler one, though I dont know how to generate mouse events (mousedown/up). For that, winapi would be the thing
to resort to

anyways, got a nice snippet of using winapi from your code (I am from VB background, now in c#) ;-)

<Kalpesh/>
 
* said:
Would Button1.PerformClick() do ?
rather simpler one, though I dont know how to generate mouse events
(mousedown/up). For that, winapi would be the thing to resort to

It will work, but it won't /visually/ press the button. It will only
call the 'Click' event handlers.
anyways, got a nice snippet of using winapi from your code (I am from VB background, now in c#) ;-)

;-(
 
Back
Top