Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Checking if button was clicked on second time

I want to check if a button is clicked with c#

like this

private void btnFillo_Click(object sender, EventArgs e)
{
    btnFillo.Text = "text";

  //  if (btnFillo clicked again) {
        // do something
  //  }
}
like image 415
Gassalam Frans Avatar asked Nov 21 '25 06:11

Gassalam Frans


1 Answers

      private int  clickCounter = 0;
      private void btnFillo_Click (object sender, EventArgs e) {
         btnFillo.Text = "text";

         if (clickCounter >= 1) {
         // do something
         clickCounter = 0;
         }
         else  clickCounter += 1;
      }

if you want to do something just on second clicks simply use a boolean:

      private bool  isClicked = false;
      private void btnFillo_Click (object sender, EventArgs e) {
         btnFillo.Text = "text";

         if (isClicked) {
         // do something
            isClicked = false;
         } else isClicked = true;
      }
like image 195
AliReza Sabouri Avatar answered Nov 22 '25 18:11

AliReza Sabouri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!