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

  • 相关阅读:
    0x01 虚拟环境搭建
    python操作mysql8windows环境
    Navicat 导入sql文件执行失败问题的处理
    mysql8.0.16免安装教程
    zend studio 9.0.3 注册码
    oneplus8手机蓝牙连接tws耳机无法双击退出语音助手
    竞品分析
    源码阅读方法
    Tomcat内核1
    Asp.NetCore3.1开源项目升级为.Net6.0
  • 原文地址:https://www.cnblogs.com/haimingkaifa/p/5732217.html
Copyright © 2011-2022 走看看