Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# Refresh a windows form

Tags:

c#

winforms

I have a windows form which has to be refreshed automatically without using any button to refresh the form.

Right now am using a button to refresh the form. But I need the form to refresh automatically for every 1 minute.

It is possible to do in windows form application.

like image 788
bharathi Avatar asked May 10 '11 05:05

bharathi


2 Answers

I'm not sure why you need to refresh a form, but put whatever code you have behind the button in a timer event. You already have the code, so just create a timer, set it for the length you want, and turn it on.

Here is the code you need:

  Timer myTimer = new Timer();
  myTimer.Elapsed += new ElapsedEventHandler( TimeUp );
  myTimer.Interval = 1000;
  myTimer.Start();

public static void TimeUp( object source, ElapsedEventArgs e )
{
    //Your code here
}
like image 128
IAmTimCorey Avatar answered Sep 21 '22 05:09

IAmTimCorey


You can add a Timer to the form and enable it on Form_Load. Set the timer value in milliseconds to 60000. In the Timer_Tick function, you can put the code meant for refreshing.

like image 37
Khemka Avatar answered Sep 20 '22 05:09

Khemka