c# - Datetime Timer Interval does not change speed of months added -
datetime newdate = new datetime(2013, 1, 1); void addtime() { timer1.interval = 600000; timer1.enabled = true; timer1.tick += new eventhandler(timer1_tick); timer1.start(); } void timer1_tick(object sender, eventargs e) { newdate = newdate.addmonths(+3); lbldate.text = newdate.tostring(); }
for reason changing timer1.interval
not change speed of 3 months being added newdate
, constant. trying have 1 minute real life time equal 3 months in game. using c#.
your initial timer interval bit larger. below sample complete application. working expected
using system; using system.windows.forms; namespace windowsformsapplication1 { public partial class form1 : form { datetime newdate = new datetime(2013, 1, 1); public form1() { initializecomponent(); addtime(); // call method, otherwise timer not start } void addtime() { timer1.interval = 60000; // every minute (1 minute = 60000 milliseconds) timer1.enabled = true; timer1.tick += new eventhandler(timer1_tick); timer1.start(); } void timer1_tick(object sender, eventargs e) { newdate = newdate.addmonths(3); label1.text = newdate.tostring(); } // if need set timet interval after timer start, below private void button1_click(object sender, eventargs e) { timer1.stop(); timer1.interval = 30000; // set interval 30 seconds timer1.start(); } } }
Comments
Post a Comment