• 利用委托传值


     public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
            public Form2(string str,Delegate de) : this()//调用当前空构造函数
            {
                label1.Text = str; //赋值
                this.de = de;//赋值     
            }
            private void Form2_Load(object sender, EventArgs e)
            {

            }
            private Delegate de;//定义委托类型字段
            private void button1_Click(object sender, EventArgs e)
            {
                string strmsg = textBox1.Text;
                if (de != null)
                {
                    de(strmsg); //委托类型
                }
                this.Close();
            }
        }

     public Main1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                string content = textBox1.Text;
                Form2 frm2 = new Form2(content,MsgStr); //初始化构造函数并赋值,参数中有需要委托类型(注:委托类型)
                frm2.Show();
            }
            private void MsgStr(string str)
            {
                textBox2.Text = str;
            }
        }

  • 相关阅读:
    冲刺2 05
    冲刺02 04
    人月神话阅读笔记01
    进度条
    团队冲刺第十天
    团队冲刺第九天
    学习进度条13
    团队冲刺第八天
    怎样买书更便宜
    冲刺第七天
  • 原文地址:https://www.cnblogs.com/haimingkaifa/p/5732217.html
Copyright © 2020-2023  润新知