Hi. i need to count the number of times a button has been clicked in C# windows application. for asp websites i know how to do it using viewstates but i dont know how to do it with windows form application. Any help will be greatly appreciated.

Yee, look this code:

int intClicks;
        private void button1_Click(object sender, EventArgs e)
        {
            intClicks++;
            MessageBox.Show("button has been clicked " + intClicks + (intClicks == 1 ? " time." : " times."));
        }
private void btnlogin_Click(object sender, EventArgs e)
        {
            
            count++;
            if (count <= 3)
            {
                login();
            }
            else
            {
                MessageBox.Show("3");
            }
        }

this is what i was doing!! and i found the error! the "int count = 0;" was setting count to zero outputing 1 every time! so ive removed it and added it as a global variable. But still thanks a lot for replying!

This question has already been answered. Start a new discussion instead.