简体   繁体   中英

Title show while timer is enabled

so I have a problem where I want to make a label pop up when timer is enabled. I tried writing this but it just doesn't work. I have set every object property as needed, but still there is some kind of problem. Can you help me please? Thanks.

private void timer1_Tick(object sender, EventArgs e)
    {
        if (button3Click == true && FullNameBOX.Text == "")
        {
            timer1.Start();
             while(timer1.Enabled == true)
            {
                label5.Show();
            }
            
            timer1.Stop();

        }
        else if(timer1.Enabled == false)
        {
            label5.Hide();
        }
        else
        {

        }

timer1_Tick is only executed once the timer is started and the timer interval is elapsed for the first time and then repeatedly every interval. So you must start the timer somewhere else. In button button3_Click I assume

private void button3_Click(object sender, EventArgs e)
{
    if (FullNameBOX.Text == "")
    {
        label5.Show();
        timer1.Start();
    }
    else
    {
        ... process the FullNameBOX.Text
    }
}

In the Tick event handler stop the timer and hide the label

private void timer1_Tick(object sender, EventArgs e)
{
    timer1.Stop();
    label5.Hide();
}

Also, give better names to your controls. It's best to do so before creating the event handlers so that those get better names too. It is easier to understand messageLabel than label5 and SaveButton_Click than button3_Click .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM