所以我試圖做一個答題器遊戲,並且我爲Factory升級設置了一個計時器。 Cookie更新,但在後臺。每秒自動更新標籤
標籤不會更新,直到您點擊Main
按鈕(以提高cookie數量)。我試過CookieCount.Refresh()
或Refresh()
(CookieCount
是我想每秒更新一次的標籤)。
public Form1()
{
InitializeComponent();
TRIPLECBTN.Hide();
// Create a timer with a ten second interval.
aTimer = new System.Timers.Timer(10000);
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 1000;
aTimer.Enabled = false;
}
public void OnTimedEvent(object source, ElapsedEventArgs e)
{
cookies = cookies + 1;
}
public void button3_Click(object sender, EventArgs e)
{
if (cookies >= 1)
{
FACTORYBTN.Hide();
INFO1.Hide();
COST1.Hide();
PRICE1.Hide();
cookies -= 250;
MessageBox.Show("You have bought Factory!");
aTimer.Enabled = true;
}
}
(有一些行之間,但他們並不重要)。
WinForms應使用WinForms計時器。 – LarsTech
你究竟想要完成什麼?什麼工作,什麼不工作? –
除非您單擊增加cookie數量的按鈕,否則每次添加cookie時標籤都不會更新(每秒)。但它確實在後臺計數。 – byIcee