I have a problem. So i was trying to do simple cliker using button: it counts button clicks. I was searching it on internet and tryed this code:
{
int intClicks = 0;
intClicks++;
for (int i = 0; i < 10; i++) {
Lab1.Text = ("button has been clicked " + intClicks + (intClicks == 1 ? " time." : " times."));
}
}
But it only count once. I don't have idea how to reapiar this.
I want it to count EVERY button click.
As @Good Night Nerd Pride mentioned, you "forgetting" clicks count by resetting it to 0 at each button click.
To "remember" clicks count, your
intvariable should be declared somewhere out of Button.Click event handler scope.From "Lab1.Text" i decided that you using Windows Forms (
Labelcontrol withTextproperty), so declaringintvariable to "remember" total clicks count out of Button.Click event handler may look like this:And when you need to reset it - you probably want some other
Button, which sets_totalClicksvariable to 0 (and clearsLabel.Textif needed):