将数组从一个按钮传递到另一个按钮
问题描述:
您好,如何将一个按钮中的整数数组传递给另一个按钮?这里是更多信息:
以下代码与我的原始代码不完全相同,但是它说明了我要问的问题.
Hello, How can I pass an array of integer from a button to another one?Here is more information:
the following code is not exactly my original code, but It explains what I''m asking.
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中的array2.该怎么做?
在此先谢谢您.
Now I want to access array2 in button2.How can I do that?
Thanks in advance.
答
在您的表单中声明一个动态大小的数组,并在两个函数中都使用它.
所以声明
Declare a dynamic sized array in you form and use it in both functions.
So declare
int [,] array2;
并在您的函数中使用它.
in your form and use it in your functions.
private void button1_Click(object sender, EventArgs e)
{
int[,] array1 = new int[pictureBox1.Height, pictureBox1.Width];
array2 = new int[pictureBox1.Height, pictureBox1.Width];
array2 = binary(array1);//binary is a function
}
private void button2_Click(object sender, EventArgs e)
{
// Use array2 here.
}
在表单中使用变量来传递值,方法是设置一个变量并读取另一个变量.
Use a variable within your form to transfer the values, by setting in one and reading in the other.