zoukankan      html  css  js  c++  java
  • winform 父窗体与子窗体数据传递

    简单实例截图:

     父窗体代码如下:


    public partial class Form1 : Form
    {
    Child2 child2 = new Child2();
    public Form1()
    {
    InitializeComponent();
    child2.receive += new Child2.receiveData(testReceive);
    }

    private void button2_Click(object sender, EventArgs e)
    {
    string ls = textBox1.Text;
    for(int i=0;i< child2.Controls.Count; i++)
    {
    Control c = child2.Controls[i];
    if (c.Name == "txtReceive")
    {
    c.Text = "通过查找控件传递数据:"+ls;
    }
    }

    child2.getReceiveData("通过函数传递数据:"+ls);

    }

    private void button3_Click(object sender, EventArgs e)
    {
    child2.Show();
    }

    private void testReceive(object o)
    {
    textBox2.Text = o.ToString();
    }
    }

    子窗体代码如下:

    public partial class Child2 : Form
    {
    public delegate void receiveData(object o);
    public event receiveData receive;
    public Child2()
    {
    InitializeComponent();
    }

    public void getReceiveData(object o)
    {
    txtReceive2.Text = o.ToString();
    }
    public void Receive(object o)
    {
    receive(o);
    }

    private void button1_Click(object sender, EventArgs e)
    {
    Receive(txtReceive3.Text);
    }
    }

    一个简单的父子窗体数据传递。亲测,可以实现上面的效果,谢谢!

  • 相关阅读:
    CSU1784
    HDU 6128 Inverse of sum(数学)
    容斥原理入门
    HDU 6129 Just do it(规律)
    HDU 6140 Hybrid Crystals(zz)
    HDU 6143 Killer Names(排列+容斥,dp)
    zzuli 2177 Contest
    zzuli 2180 GJJ的日常之沉迷数学(逆元)
    除法逆元入门
    乘法逆元数论篇
  • 原文地址:https://www.cnblogs.com/Seamless/p/15216735.html
Copyright © 2011-2022 走看看