2011-10-18 141 views
1

如何將一個整數數組從一個按鈕傳遞到另一個按鈕?將數組從一個按鈕傳遞到另一個按鈕

下面是詳細信息(下面的代碼是不完全的我原來的代碼,但它說明了我在問什麼):

private void button1_Click(object sender, EventArgs e) 
{ 
    int[,] array1 = new int[pictureBox1.Height, pictureBox1.Width]; 
    int[,] array2 = new int[pictureBox1.Height, pictureBox1.Width]; 

    array2 = binary(array1);//binary is a function 
} 

private void button2_Click(object sender, EventArgs e) 
{ 
    //I need array2 here 
} 

現在我想在BUTTON2訪問數組2。我怎樣才能做到這一點?什麼是最好的解決方案?

在此先感謝。

+2

看看http://en.wikipedia.org/wiki/Magic_pushbutton –

回答

4

外貌就像第一個按鈕點擊你準備一些數據,而第二個按鈕點擊你將使用它一些如何。

可以使用類級變量共享一個磁盤陣列:

class YourClass 
{ 
    private int[,] data; 

    private void button1_Click(object sender, EventArgs e) 
    { 
    this.data = new ... 
    } 

    private void button2_Click(object sender, EventArgs e) 
    { 
    // process a data 
    if (this.data != null) 
    { 
     this.data ... 
    } 
    } 
} 
0

只是聲明數組的button_Click事件的代碼之外,將其變爲私有所以它的你在類中唯一accessable,那麼你可以從任何方法/事件處理程序,在該類訪問

相關問題