2015-04-12 84 views
-2

當我嘗試從不同勢按鈕來訪問布爾變量喜歡這裏:訪問按鈕的變量

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; 
     } 

謝謝。

+0

是否確定你剛剛做了,你在第一個按鈕中聲明瞭一個局部變量nd你想從外部函數中改變它的值 –

回答

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; 
}