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
// }
}
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
// }
}
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;
}
You have to save click in a global variable, such as
clicked += 1
where clicked variable is a global variable (var clicked = 0). And after:
if(clicked > 1)
or use Control.MouseDoubleClick Event: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.mousedoubleclick?redirectedfrom=MSDN&view=netframework-4.8
thanks all for the help i solve my problem... I post the code for other if they need this.
private int clickCounter = 0;
private void btnFillo_Click(object sender, EventArgs e)
{
if(clickCounter == 0 ) {
// first time click
btnFillo.Text = "text";
clickCounter++;
}
else if (clickCounter == 1)
{
// second time click
btnFillo.Text = "heeeeellll";
clickCounter++;
}
else if (clickCounter == 2)
{
// third time click
btnFillo.Text = "change 2";
clickCounter = 0;
}
else // you can do more if you want more clicks
{
clickCounter += 1;
}
}