荆门龙泉高中喜报2016:窗体间的数值传递 方式1

来源:百度文库 编辑:九乡新闻网 时间:2024/07/07 13:40:33
有很多种方法,我给你个最简单的吧,(form2 上一个button1,form1 上一个textbox1,实现的功能:点击form2中的button1,把button1的text值传给form1并在form1中的textbox1中显示)代码如下: public partial class Form1 : Form    {        private string _canshu;        public Form1()        {            InitializeComponent();        }        public Form1(string canshu)         {            InitializeComponent();            _canshu = canshu;//form2调用时把参数传过来            this.textBox1.Text = _canshu;        }    }    public partial class Form2 : Form    {        public Form2()        {            InitializeComponent();        }
        private void button1_Click(object sender, EventArgs e)        {            Form1 f = new Form1(this.button1.Text);//把值传过去并显示            f.Show();        }    }