zoukankan      html  css  js  c++  java
  • C# 利用委托完成窗体间传数据

    主窗体:form1

    参数设置窗体:form4

    首先在form4中设置委托和事件

    public delegate void TransfDelegate(string value,double dv, int naction,string addr, string id);

    public event TransfDelegate TransfEvent;

    按钮触发事件

            private void button1_Click(object sender, EventArgs e)
            {
                if (textBoxName.Text.Length == 0)
                {
                    MessageBox.Show("姓名不能为空");
                    return;
                }

                if (textBoxWeight.Text.Length == 0)
                {
                    MessageBox.Show("体重不能为空");
                    return;
                }

                name = textBoxName.Text;
                weight = Convert.ToDouble(textBoxWeight.Text);
                action = comboBoxAction.SelectedIndex;
                address = comboBoxAddress.SelectedItem.ToString();
                deviceid = comboBoxDevice.SelectedItem.ToString();

                //触发事件,传递样本名字,体重,动作,地址,设备号
                TransfEvent(name, weight, action, address, deviceid);
                this.Close();
            }

    主窗体中按钮事件打开参数设置窗体form4,在事件中处理传递过来的参数

            private void buttonSave_Click(object sender, EventArgs e)
            {
                fillPatientInfo();

                //save data to database

               ......

      }

            private void fillPatientInfo()
            {
                Form4 logForm = new Form4();
                logForm.TransfEvent += frm_TransfEvent;
                logForm.ShowDialog();
            }

            //事件处理方法
            void frm_TransfEvent(string value, double dv, int naction, string addr, string id)
            {
                name = value;
                weight = dv;
                action = naction;
                address = addr;
                deviceid = id;
            }

  • 相关阅读:
    实现简易赈灾物资发放登记系统---练习
    数据访问-----ADO.NET 练习2
    数据访问-----ADO.NET 练习1
    面向对象(3)继承
    面向对象(2)
    面向对象(1)
    JavaScript 内容串联 ---Document---四、五和正则表达式。
    JavaScript 内容串联 ---Document
    document--操作相关元素(js简短汇总3)
    js--document对象操作内容(js简短汇总2)
  • 原文地址:https://www.cnblogs.com/xyzrobot/p/7517724.html
Copyright © 2011-2022 走看看