将数组从一个按钮传递到另一个按钮 [英] passing an array from one button to another

查看:95
本文介绍了将数组从一个按钮传递到另一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,如何将一个按钮中的整数数组传递给另一个按钮?这里是更多信息:
以下代码与我的原始代码不完全相同,但是它说明了我要问的问题.

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.


这篇关于将数组从一个按钮传递到另一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆