how to refresh button in C# windows application?
.net
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ranjit PowarRank #553 · 4.4K reputationPosted Mar 10, 2015, 1:37 AM EDT
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Mar 10, 2015, 1:38 AM EDT
What you have, should refresh the current form that that event belongs to. It is hard to make out what your problem is due to the lack of intelligable information (what is happening and why are you saying it does not work? etc.). However, you could try
private void Refresh_Click(object sender, EventArgs e)
{
this.Update();
}
The difference between the two methods is thus:
Control.Update()
The Update() function calls the UpdateWindow function which updates the client area of the control by sending WM_PAINT message to the window (of the control) if the window's update region is not empty. This function sends a WM_PAINT directly to WNDPROC() bypassing the application message queue.
Thus, if the window update region is previously "invalidated" then calling "update" would immediately "update" (and cause repaint) the invalidation.
Control.Refresh()
Refresh() calls Invalidate(true) to invalidate the control and its children and then calls Update() to force paint the control so that the invalidation is synchronous.
I hope this helps.