从不同的按钮(c#表单)访问按钮的变量

时间:2015-04-12 13:00:59

标签: c#

当我尝试从不同的按钮访问bool变量时,如下所示:

    private void button1_Click(object sender, EventArgs e)
    {
        //Those my bool variable I want to access from the second button
        bool second = false , third = false , forth = false , fifth = false;
    }
       private void button4_Click(object sender, EventArgs e)
        {
           //Here is where I try to access, but i can't.
            second = true;
        }

谢谢。

1 个答案:

答案 0 :(得分:0)

您只需将它们设置为全局变量即可。

bool second, third , forth , fifth = false;
private void button1_Click(object sender, EventArgs e)
{
    //Those my bool variable I want to access from the second button
    second = false; 
    third = false; 
    forth = false; 
    fifth = false;
}
private void button4_Click(object sender, EventArgs e)
{
    second = true;
}