none
An event happens after I press two buttons RRS feed

All replies

  • This is the C# forums. We don't provide support for UI stuff here. Please identify what type of UI application you're building so we can move your question to the correct forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, August 28, 2018 5:44 PM
    Moderator
  • Use a boolean variable. In the click event for the first button, set the variable to true. In the Click for the second button, check the variable; if it's true it means that both buttons were pressed, in which case you execute the thing that you want to happen (and then reset the variable to false if you need to be able to detect a second pressing of the two buttons). This presumes that bot buttons are always pressed in the same order. If you want both in any order then use two boolean variables and repeat the previous procedure using one variable for each button.

    Example:

    private bool button1clicked = false;
    private bool button2clicked = false;
    
    private void Button1Click(object sender, EventArgs e)
    {
        button1clicked = true;
        DoSomethingIfBothClicked();
    }
    
    private void Button2Click(object sender, EventArgs e)
    {
        button2clicked = true;
        DoSomethingIfBothClicked();
    }
    
    private DoSomethingIfBothClicked()
    {
        if (button1clicked && button2clicked)
        {
            // Do here whatever you want to happen
        }
    }

    Tuesday, August 28, 2018 6:30 PM
    Moderator