C#窗口数据委托

csharp

浏览数:586

2019-1-7

namespace winlogin
{
    public partial class Wdata : Form// 子窗口
    {        
        //委托事件
        public delegate void TransfDelegate(Dictionary<string, string> value);
        public event TransfDelegate TransfEvent;
        //----------------------------
        public Wdata()
        {
            InitializeComponent();     
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Dictionary<string, string> MSG = new Dictionary<string, string>();
            MSG.Add("AAAAA", "CCCCC");
            MSG.Add("BBBBB", "DDDDD");
            TransfEvent(MSG);//传输到委托事件
        }

        private void Wdata_FormClosing(object sender, FormClosingEventArgs e)
        {
            MessageBox.Show("11111111111111");
        }
    }
}namespace winlogin//主窗口
{
    public partial class AddData : CCSkinMain
    {
      
        public AddData(string msg)
        {
            InitializeComponent();            
        }
      
        private void button2_Click(object sender, System.EventArgs e)
        {
            Wdata wd = new Wdata();
            wd.TransfEvent += frm_TransfEvent;//加入委托事件
            wd.ShowDialog();
        }
        void frm_TransfEvent(Dictionary<string, string> value)//读数和显示
        {
            textBox2.Text = value["BBBBB"].ToString();
            textBox3.Text = value["AAAAA"].ToString();
        }
    }
}