C # Refresh Window Form

I have a window form that needs to be updated automatically without using any button to update the form.

Now I use the button to refresh the form. But I need a form to update automatically every 1 minute.

This can be done in a Windows Form application.

+4
source share
5 answers

I'm not sure why you need to update the form, but put the code that you have for the button in the timer event. You already have the code, so just create a timer, set it to the desired length 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 } 
+4
source

You can add Timer to the form and include it in Form_Load. Set the timer value in milliseconds to 60,000. In the Timer_Tick function, you can put the code for updating.

+2
source

Use the timer control and set the interval as 60 * 1000 ms (1 min), and in the check event use the code to update the form.

+1
source

Use System.Windows.Forms.Timer .

Timer.Tick event Occurs when the specified timer interval has expired and the timer is on. You can use it to update the form.

  // This is the method to run when the timer is raised. private static void Timer_Tick(Object myObject, EventArgs myEventArgs) { // Refresh Form } 

Use the Timer.Interval property to specify a timer interval. In your case, you need to set it to 60,000:

 Timer.Interval = 60000; 

Here are some of them:

http://www.codeproject.com/KB/cs/timeralarm.aspx

http://www.dotnetperls.com/timer

http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingwithTimerControlinCSharp11302005054911AM/WorkingwithTimerControlinCSharp.aspx

+1
source

Do it! Step by step:

  • Add a timer to your form
  • Set ( Interval ) to 1000
  • Double click on the form
  • Enter this for Form_Load:

    timer1.Start(); //Set your timer name instead of "timer1"

  • Double click on the timer and enter it for timer_tick:

    this.Refresh();

0
source

All Articles