Monday, 15 July 2013

c# - reset button for a simple counter -



c# - reset button for a simple counter -

i'm making pretty simple counter app windows 7.1 in c# using visual studios 2010.

i've added 2 buttons, 1 + , 1 - (for adding or subtracting). results beingness printed out textblock works fine.

now i'm trying add together reset button set value in textblock 0 , i'm struggling. can create come out 0 tostring counter value doesn't reset zero!

i realise it's simple problem prepare i'm coming blank! thanks.

using system; using system.collections.generic; using system.linq; using system.net; using system.windows; using system.windows.controls; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.animation; using system.windows.shapes; using microsoft.phone.controls; namespace phoneapp1 { public partial class mainpage : phoneapplicationpage { int counter = 0; // constructor public mainpage() { initializecomponent(); } private void add_tap(object sender, gestureeventargs e) { counter++; number.text = counter.tostring(); } private void subtract_tap(object sender, gestureeventargs e) { counter--; number.text = counter.tostring(); } private void button1_tap(object sender, gestureeventargs e) { //need create clicking button reset number(textblock) 0 } }

}

private void button1_tap(object sender, gestureeventargs e) { counter = 0; number.text = counter.tostring(); }

you give textbox , counter number want set.

the reason why cannot utilize tostring() on counter-variable is, because counter integer , no string, , tostring() returns string.

c# .net wpf counter

No comments:

Post a Comment