5

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.

4 Answers 4

9

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

Sign up to request clarification or add additional context in comments.

4 Comments

+1 for the alternative to PerformClick. PerformClick is a hackish approach in production code. I think it should generally be limited to testing.
My fault; I assumed it was a button, but it's actually a link label that acts like a button. Is there a similar method for those?
msdn.microsoft.com/en-us/library/bb337532.aspx, but as you said, a separate method is better.
@Yuriy: many thanks, I didn't know that. I've modified my post ;)
5

You could call the PerformClick method. But Generally it is better to have the Click event of the button call a Refresh method you write. And the menu call that method as well. Otherwise your menu depends on the button being there.

Edit:

A LinkLabel implements the IButtonControl explicitly. So you could use:

((IButtonControl)button).PerformClick();

Comments

0

you can use a method to refrech display, the bouton_click and the dialogBox call this method

public void refrechDate()
{
}


private void button_click(...)
{
   refrechData();
}

Comments

0
private void MyMethod()
{
   // ...

   // calling refresh
   this.button1_Click(this.button1, EventArgs.Empty);

   // ...
}

private void button1_Click(object sender, EventArgs e)
{
   // refresh code
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.