zoukankan      html  css  js  c++  java
  • C# 窗口传值的方法

    方法一: A to B 

    设置FormB 为 带参数的构造函数

    public Form2( object msg)
    {
    InitializeComponent();
    }
    

     方法二: A to B  

    定义一个public 函数

        public void Receive(string Msg)
            {
                txtInfo.Text = Msg;
                this.Show();
            }
    

     方法三: 两个窗口间相互传值

    需要互传时 方法二可以实现 参数传递 但是不能及时更新接收窗口控件的显示,所以建议使用委托的方法。

    Form1:

      private void btnShow_Click(object sender, EventArgs e)
            {
                Form2 f2 = new Form2();
                f2.MyEvent += new Form2.MyDelegate(MyEvent);
                f2.Receive(txtInfo1.Text);
            }
            void MyEvent(string msg)
            {
                txtInfo1.Text = msg;
            }
    

    Form2:

            public delegate void MyDelegate(string msg);
            public event MyDelegate MyEvent;
    
            private void btnSend_Click(object sender, EventArgs e)
            {
                MyEvent(txtInfo.Text);
            }
    

      

  • 相关阅读:
    POJ 2065 高斯消元求解问题
    HDU1045-Fire Net
    HDU1863-畅通工程
    POJ2524-Ubiquitous Religions
    POJ1064-Cable master
    POJ2456-Aggressive cows
    HDU1272-小希迷宫
    POJ1611-The Suspects
    HDU4496-D-City
    HDU1232-畅通工程
  • 原文地址:https://www.cnblogs.com/Ares-blog/p/4267362.html
Copyright © 2011-2022 走看看