c# - Pass an integer to a timer in WinForms application -
i have winforms built in timer:
system.windows.forms.timer timerloop;
when timer started, want (if possible) pass timer integer value.
timerloop.start();
till now, created general variable timer can read , update variable before starting timer.
you can 2 ways (maybe more):
extend base timer
creating new 1 inherit it:
private class timerexnteded : timer { public int value { get; set; } public timerexnteded(int value) { value = value; } }
and use value in tick
event.
use tag
property of timer
timer t = new timer(); t.tag = 5; t.start(); //event private void t_tick(object sender, eventargs e) { var timer = sender timer; var value = (timer.tag int?) ?? 0; value++; timer.tag = value; }
second approach uses boxing/unboxing of value.
Comments
Post a Comment