zoukankan      html  css  js  c++  java
  • C# winform窗体传值 利用委托 子窗体传值给父窗体

     首先在Form2中定义委托和事件:

         //声明委托 和 事件
    
        public delegate void TransfDelegate(String value);
    
        public partial class Form2 : Form
    
        {
    
            public Form2()
    
            {
    
                InitializeComponent();
    
            }
    
    
    
            public event TransfDelegate TransfEvent; 
    
            private void button1_Click(object sender, EventArgs e)
    
            {
    
                //触发事件
    
                TransfEvent(textBox1.Text);
    
                this.Close();
    
            }
    
        }

      然后在Form1中进行调用:

        public partial class Form1 : Form
    
        {
    
            public Form1()
    
            {
    
                InitializeComponent();
    
                
    
            }
    
    
    
            private void button1_Click(object sender, EventArgs e)
    
            {
    
                Form2 frm = new Form2();
    
                //注册事件
    
                frm.TransfEvent += frm_TransfEvent;
    
                frm.ShowDialog();
    
            }
    
    
    
            //事件处理方法
    
            void frm_TransfEvent(string value)
    
            {
    
                textBox1.Text = value;
    
            }
    
        }
  • 相关阅读:
    《Troubleshooting Windows 7 Inside Out》文摘-1
    快与慢、空和满
    学习心得-4
    word::替换::突出显示
    word
    system.run
    kafka server.properties
    zookeeper.conf
    elasticsearch
    filebeat.yml
  • 原文地址:https://www.cnblogs.com/yuanmo/p/10034253.html
Copyright © 2011-2022 走看看