(Windows窗体)按钮仅在bool为true时可用

时间:2018-03-14 21:29:45

标签: forms button boolean

是否可以设置一个按钮,只有在bool为真时才可以点击? 这不是我的实际代码,但是:

bool details_accepted = false;

public bool check_bank_details()
{
    //this is simplified it's actually using an SQL query
    if (bank_details = "123456789")
    {
        return true;
    }
    else
    {
    return false;
    }
}

if (check_bank_details == true)
{
    //CODE FOR SETTING BUTTON TO CLICKABLE
}
else if (check_bank_details == false)
{
    //Code making Button not clickable
}

1 个答案:

答案 0 :(得分:1)

使用Enabled属性

Button1.Enabled = check_bank_details();