Keep value of a timer in form change

0

In my application I have a Timer that counts down from X seconds When the startup works without problems, the error comes when the form changes to the label where the remaining time loses its value. I'm using inheritance of forms, the Timer I have defined in the BASE and they have to show all their HIJOS moving by them and saving the remaining time.

    
asked by Hector Lopez 05.12.2017 в 10:35
source

2 answers

1

You can create a new class that only contains the Timer. Create an object of this new class in BASE and pass it as a parameter to the forms you want.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace proyecto{
    class MiTimer{
    protected Timer temporizador;

        public MiTimer(){
            temporizador = new Timer();
            //En caso de requerir inicializar mas variables, añadir aquí
        }

        public Timer getTimer(){
            return temporizador;
        }

        //Mas métodos que puedas necesitar aquí...
    }
}
    
answered by 06.12.2017 в 20:13
0

The final solution I gave him was to make a class where I create all the timmers (class timmer) declaring all the variables that you have to modify as statitas so that they do not lose their value in the whole execution. In the form base I declare a timer UPDATE that what it does is refresh the form every second, thus recovering all the modified values of the timmer class (for this it is necessary to do in the constructor of the base update.start ()). With this I can never lose the value and update the label of all the children. Thanks to all for the contributions.

    
answered by 07.12.2017 в 16:27