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

Re: Press a button programatically by hirf-spam-me-here

hirf-spam-me-here
Sun Dec 14 17:45:11 CST 2003

* "joe" <anonymous@discussions.microsoft.com> scripsit:
> 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
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Re: Press a button programatically by Kalpesh/>

Kalpesh/>
Mon Dec 15 00:16:15 CST 2003

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/>


Re: Press a button programatically by hirf-spam-me-here

hirf-spam-me-here
Mon Dec 15 06:16:10 CST 2003

* "<Kalpesh/>" <kalpesh@disc.microsoft.com> scripsit:
> 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#) ;-)

;-(

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>