Geoff Bowden
Geoff Bowden

Reputation: 71

How to fire click event of panel programmatically?

I have a winforms app in vs2010 and a panel whose click event I would like to fire programatically. How do I do this? Button has a PerformClick but I cannot find the same in Panel.

Upvotes: 3

Views: 3874

Answers (1)

Gusman
Gusman

Reputation: 15151

Your panel's Click event is going to be attached to an event handler, right?

Then just call that event handler from the button's click event handler:

public void Panel1_Click(object sender, EventArgs e)
{
    //Do whatever you need to do
}

public void Button1_Click(object sender, EventArgs e)
{
    //Do anything you need to do first
    Panel1_Click(Panel1, EventArgs.Empty);
}

The effect will be the same as clicking on the panel.

Upvotes: 3

Related Questions