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

  • 相关阅读:
    Gym 100418J Lucky tickets(数位dp)
    UI各种小控件的用法
    安卓系统底层C语言算法之測试參数是几个long型的算法
    Chisel Tutorial(一)——Chisel介绍
    java中super的作用
    flume採集数据导入elasticsearch 配置
    UML中的序列图(时序图)
    简单的Queue
    UNIX环境高级编程(5):文件I/O(1)
    四、基于HTTPS协议的12306抢票软件设计与实现--水平DNS并发查询分享
  • 原文地址:https://www.cnblogs.com/xyzrobot/p/7517724.html
Copyright © 2011-2022 走看看