Dwayne Dibbley
Dwayne Dibbley

Reputation: 355

Send left mouse to click handler from code?

I have the following mouseclick event:

public static void ni_MouseClick(object sender, MouseEventArgs e)
{
    // Handle mouse button clicks.
    if (e.Button == MouseButtons.Left)
    {
        //do stuff
    }
}

This is usually triggered by clicking the icon in the systray with a left click,

I would like to also call this same event from another event, I have tried something like:

myproject.ProcessIcon.ni_MouseClick(sender, mousebutton.left);

but obviously I'm not sure how to send the left button object correctly (if possible).

Upvotes: 0

Views: 473

Answers (3)

Lucifer
Lucifer

Reputation: 1600

simply change your code as below :-

ni_MouseClick(sender, new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0);

But you need to think and implement as per Ash's answer he has better solution.

Upvotes: 0

ASh
ASh

Reputation: 35733

Any operation which can be triggered by user interaction (click), can obviously be triggered by other code.

put any functionality which should be performed more than once in a separate method and invoke that method from different places in code:

public static void DoStuff()
{
}

private void ni_MouseClick(object sender, MouseEventArgs e)
{
    // Handle mouse button clicks.
    if (e.Button == MouseButtons.Left)
    {
        DoStuff();
    }
}

myproject.ProcessIcon.DoStuff();

Upvotes: 2

Xaphas
Xaphas

Reputation: 519

You have to call the method within your second method. Something like:

public void SecondMethod(object sender, Args e){
    ni_MouseClick(sender, e);
}

Upvotes: 0

Related Questions