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

  • 相关阅读:
    redis 3 通用指令
    查看表索引
    truncate的用法
    Java(0)_ 安装jdk
    Java(9)_ 集合(3)
    Java(10)_File&递归&字节流
    Java(8)_ 集合(2)
    Appium+python的单元测试框架unittest(3)——discover
    Appium+python的单元测试框架unittest(2)——fixtures
    爬楼梯
  • 原文地址:https://www.cnblogs.com/haimingkaifa/p/5732217.html
Copyright © 2011-2022 走看看