Conditional "on" and "off" on a button C #

2

As a secondary function on a button or element? For example:

private void Bnt1_Click(object sender, EventArgs e)
{   
}

private void Bnt2_Click(object sender, EventArgs e)
{
    bnt.Enabled = false;
}

In this code, when you click Bnt2 the first button is disabled, such as clicking Bnt2 again to make Bnt1 active again.

Ps: If something was not clear, let me know and I'll change it.

Ps2: The secondary function refers to the part of the conditional, "snag".

    
asked by anonymous 24.05.2017 / 12:11

1 answer

5

I do not understand the part of putting 2 functions in a button but this should serve.

private void Bnt2_Click(object sender, EventArgs e)
{
    if(bnt.Enabled)
        bnt.Enabled = false;
    else
        bnt.Enabled = true;
}

Or at the suggestion of Jefferson Quesado:

private void Bnt2_Click(object sender, EventArgs e)
{
    //valor = ao inverso do valor atual
    bnt.Enabled = !bnt.Enabled;
}
    
24.05.2017 / 12:21