c# - Automatically update label every second -


so i'm trying make clicker game , i've set timer factory upgrade. cookies update, in background.

the label not update until click main button (to raise cookie count). tried cookiecount.refresh() or refresh() (cookiecount being label want update every second).

public form1() {     initializecomponent();      triplecbtn.hide();      // create timer ten second interval.     atimer = new system.timers.timer(10000);      atimer.elapsed += new elapsedeventhandler(ontimedevent);      // set interval 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;      } } 

(there lines in between aren't important).

update label in ontimedevent count cookies.

  public void ontimedevent(object source, elapsedeventargs e)   {       cookies = cookies + 1;       label.text = yourtext   } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -