日期:2014-05-17  浏览次数:20771 次

关于textbox数据绑定问题
我想做的效果是:如下图,点击button1的时候弹出的form2能引用text1,text2的数据,点击button2的时候弹出的form2能引用text3,text4的数据.点击两个button弹出的是同一个form2,只是form2里的数据显示不同.
应该怎么处理??

------解决方案--------------------
FORM1的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LINQTEST.CSDN.页面传值
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 frm = new Form2();
            frm.str1 = this.textBox1.Text;
            frm.str2 = this.textBox2.Text;
            frm.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 frm = new Form2();
            frm.str1 = this.textBox3.Text;
            frm.str2 = this.textBox4.Text;
            frm.Show();
        }
    }
}


FORM2的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LINQTEST.CSDN.页面传值
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }


        public string str1;
        public string str2;
        private void Form2_Load(object sender, EventArgs e)
        {
            this.textBox1.Text = str1;
            this.textBox2.Text = str2;
 &