窗体传值

来源:互联网 发布:淘宝兴奋饮料 编辑:程序博客网 时间:2024/06/11 22:35

Form1代码如下:

        private void button1_Click(object sender, EventArgs e)        {            Form2 fr2 = new Form2(ShowMag);//传递方法            fr2.Show();        }         //赋值方法        void ShowMag(string str)        {            this.label1.Text = str;        }    

Form2代码如下:

    //声明一个委托,delegate    public delegate void DelTest(string str);    public partial class Form2 : Form    {        public DelTest _del;        //构造方法        public Form2(DelTest del)        {            this._del = del;            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            _del(this.textBox1.Text);        }    }

 

0 0
原创粉丝点击