zoukankan      html  css  js  c++  java
  • 利用委托传值

     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;
            }
        }

  • 相关阅读:
    商户编号前三位代码对应的收单机构大全
    使用邮件模板(freemarker.jar)发送邮件
    Struts2自定义拦截器
    如何在jsp页面显示存储在数据库的图片
    正则表达式 大于0的数字(包含小数)
    Linux的关机命令
    maven的下载和安装
    web.py的安装
    安装第三方插件BeautifulSoup
    myeclipse离线安装pydev插件
  • 原文地址:https://www.cnblogs.com/haimingkaifa/p/5732217.html
Copyright © 2011-2022 走看看