2011-10-18 142 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,那么你可以从任何方法/事件处理程序,在该类访问

相关问题