Good, I am making a mini system in window form that when there are 2 buttons
1: first button called draw is for it to appear for a certain time and my 8 label numbers appear 2: regenerate button is only to whiten, that is, to make them visible again
but my problem is that when I first put the draw button it is displayed correctly for a certain time,
now when it finishes and I put the second button and then I press the first button now it shows me suddenly.
this is the view part of the window form
This is my code for the first button:
private void button3_Click(object sender, EventArgs e)
{
SetInterval(1000, (obj, ev) =>
{
if (!lbln1.Visible)
{
lbln1.Show();
}
else if (!lbln2.Visible)
{
lbln2.Show();
}
else if (!lbln3.Visible)
{
lbln3.Show();
}
else if (!lbln4.Visible)
{
lbln4.Show();
}
else if (!lbln5.Visible)
{
lbln5.Show();
}
else if (!lbln6.Visible)
{
lbln6.Show();
}
else if (!lbln7.Visible)
{
lbln7.Show();
}
else if (!lbln8.Visible)
{
lbln8.Show();
}
else if (!label1.Visible)
{
label1.Show();
}
else if (!lblcliente.Visible)
{
lblcliente.Show();
}
else if (!lbloficina.Visible)
{
lbloficina.Show();
}
else if (!lblfelicitaciones.Visible)
{
lblfelicitaciones.Show();
}
else if (!lbldireccion.Visible)
{
lbldireccion.Show();
}
});
}
Second Button:
private void button1_Click(object sender, EventArgs e)
{
DialogResult res = MessageBox.Show("Desea Sortear Nuevamente?", "Aviso del sistema",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (res == DialogResult.Yes)
{lbln1.Text = "";
lbln2.Text = "";
lbln3.Text = "";
lbln4.Text = "";
lbln5.Text = "";
lbln6.Text = "";
lbln7.Text = "";
lbln8.Text = "";
lblcliente.Text = "";
lblfelicitaciones.Text = "";
lblnoesganador.Text = "";
lbloficina.Text = "";
lbldireccion.Text = "";
label1.Text = "";
MessageBox.Show("Se regenero el sorteo correctamente", "Aviso del Sistema");
button2.Enabled = false;
}
}
this is my void SetInterval
private void SetInterval(int interval, EventHandler callback)
{
//Creo el temporizador
Timer timer = new Timer();
//Le establezco el intervalo en el que va a repetir la operación
//timer.Interval = interval;
timer.Interval = interval;
//Asigno que se ejecutara al llegar el tiempo estimado
timer.Tick += (obj, ev) =>
{
//En este caso ejecuto el callback que paso como parametro
callback(obj, ev);
};
//Inicializo el temporizador
timer.Start();
}
You are complicating something, which
winforms
is done with the form controls themselves.Add 6 labels, 2 buttons and a TIMER control to the form.
leave the default names, except the del
timer
, change it totmrMostrar
and set the propertyinterval
to 1000.You're going to have to connect the events I describe below to your controls. There is an event for the first button, another for the second, and a tick event for the timer.
The simplified code with explanations in the comments is:
This code will display one
label
per second, until the last one is reached.