C# Mouse click

  • Thread starter Thread starter Shlomi Schwartz
  • Start date Start date
S

Shlomi Schwartz

Hi all

Q: what is the way to programmatically imitate a mouse left click and
mouse context menu click in c#?

Thanks ;-)
 
If you're talking about responding to mouse events in a Form you have to
install an event handler for the OnClick event of the control you want to
respond to. For instance, the handler for a button event might look like so:

private void button1_Click(object sender, System.EventArgs e)

{ MessageBox.Show("bla bla bla..."); }



to attach the method to the button handler:

this.button1.Click += new System.EventHandler(this.button1_Click);
 
Yeah, I have an *unfinished* wrapper around a number of Win32 api calls that
do this and other things (the Mouse Left click code works but isn't well
tested so use at your own risk etc, you could modify for Right-click as
well) . My Web host is acting up on me so I can't post the file for all to
download, but if you send my an email I'll send you a .zip with the code.

R.
 
Shlomi,

When it is for a button there is the performclick
(And you need the handler as showed by others)

I hope this helps

Cor
 
Back
Top