Restart winodws form in c # after inactivity

0

It is possible that the values of my form windows (digase labels, textbox, picturebox, datagrids) are deleted or return to their null value after a certain time has passed and, if possible, how or what is the method to achieve this?

And if someone has a small example of what to do, it is appreciated too but any help is welcome

    
asked by sullivan96 03.03.2018 в 03:15
source

1 answer

2

For what you propose you can use System.Windows.Forms.Timer. In the following example, after 10 seconds, a text box is deleted (this behavior is defined in the timer handler (timer1_Tick), it stops with a Stop on the Timer instance.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            textBox1.Text = string.Empty;
        }

        private void setTimer()
        {
            System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();

            t.Interval = 10000; // Especificas el tiempo que queres en milisegundos. En este caso le puse 10 segundos
            t.Tick += new EventHandler(timer1_Tick);
            t.Start();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            setTimer();

        }

    }

}

Greetings and I hope it is of your use.

    
answered by 03.03.2018 / 05:22
source