Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Triggering a "Click" event without user input

I have a Windows Forms Link Label, "Refresh", that refreshes the display.

In another part of my code, part of a separate windows form, I have a dialog that changes the data loaded into the display in the first place. After executing this other code, pressing "Refresh" updates the data correctly.

Is there a simple way for the dialog menu to "click" the "refresh" Link Label after it has finished altering the data?

Using Visual Studio 2008.

like image 497
Raven Dreamer Avatar asked Jul 06 '10 15:07

Raven Dreamer


1 Answers

For button is really simple, just use:

button.PerformClick()

Anyway, I'd prefer to do something like:

private void button_Click(object sender, EventArgs e)
{
   DoRefresh();
}

public void DoRefresh()
{
   // refreshing code
}

and call DoRefresh() instead of PerformClick()


EDIT (according to OP changes):

You can still use my second solution, that is far preferable:

private void linkLabel_Click(object sender, EventArgs e)
{
   DoRefresh();
}

public void DoRefresh()
{
   // refreshing code
}

And from outside the form, you can call DoRefresh() as it is marked public.

But, if you really need to programmatically generate a click, just look at Yuriy-Faktorovich's Answer

like image 154
digEmAll Avatar answered Oct 05 '22 22:10

digEmAll