簡體   English   中英

啟用計時器時顯示標題

[英]Title show while timer is enabled

所以我有一個問題,我想在啟用計時器時彈出 label。 我試着寫這個,但它不起作用。 我已經根據需要設置了每個 object 屬性,但仍然存在某種問題。 你能幫我嗎? 謝謝。

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僅在定時器啟動且定時器間隔第一次結束后執行,然后在每個間隔重復執行。 所以你必須在別處啟動計時器。 在按鈕button3_Click我假設

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

在 Tick 事件處理程序中停止計時器並隱藏 label

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

此外,為您的控件提供更好的名稱。 最好在創建事件處理程序之前這樣做,這樣它們也可以獲得更好的名稱。 messageLabellabel5更容易理解, SaveButton_Clickbutton3_Click更容易理解。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM