Trying to change output for a timer in a form in c# -
i need make form in c# have timer , have label have display of timer. label need generic label @ first saying counter, when timer starts needs display count. have display number down but, needs control can tweak count, does. can't sole counter.
here assignment:
create windows application. in main form, create label named “ltickcount”. create timer named “tperiodic”, , numerical control of own choosing. each time timer “ticks” increment integer, display integer value string in ltickcount. use numerical control change update rate of timer interactively.
i think have done correctly except bold part. finish tried make string in both label , counter. know shouldn't have in both, wanted show 2 things i've tried better feedback:
namespace windowsformsapplication3 { public partial class form1 : form { public form1() { initializecomponent(); this.text = "aaaaaaaa aaaaaaaa ########"; } private void checkbox1_checkedchanged(object sender, eventargs e) { if (checkbox1.checked) { tickcounter.text = "the timer has started"; tperiodic.enabled = true; } else { tickcounter.text = "the timer has ended"; tperiodic.enabled = false; } } private void tickcounter_valuechanged(object sender, eventargs e) { tickcounter.text = tickcounter.value.tostring(); } private void tperiodic_tick(object sender, eventargs e) { tickcounter.value += 1; } private void label1_click(object sender, eventargs e) { tickcounter.text = tickcounter.value.tostring(); } private void form1_load(object sender, eventargs e) { } } }
can me figure out i'm doing wrong , point me in right way?
if going try add string (a label value) need convert integer first.
a couple ways this:
textcount.text = (convert.toint32(textcount.text) + 1).tostring();
is 1 way, of course still use += or other math syntax basic addition of +1.
you can use tryparse, , in fact should used verify have integer in first place:
int count; if (int.tryparse(textcount.text, out count)) { count++; textcount.text = count.tostring(); }
Comments
Post a Comment