zoukankan      html  css  js  c++  java
  • C# 动态创建出来的窗体间的通讯 delegate2

    附件:http://files.cnblogs.com/xe2011/CSharp_WindowsForms_delegate02.rar

    窗体2 和窗体3 都是动态创建出来的

    现在 FORM3.TEXT要即时 = FORM2.TEXT

    FORM1窗体代码

            Form2 f2 = new Form2();
            Form3 f3 = new Form3();
            private void Form1_Load(object sender, EventArgs e)
            {
                f2.XYZ += new Form2.CallBack(GetForm2TextBox1Text);
    
                f2.Dock = DockStyle.Fill;
                f2.TopLevel = false;
                f2.FormBorderStyle = FormBorderStyle.FixedToolWindow;
                f2.Parent = panel1;
                f2.Show();
    
                f3.Dock = DockStyle.Fill;
                f3.TopLevel = false;
                f3.FormBorderStyle = FormBorderStyle.FixedToolWindow;
                panel2.Controls.Add(f3);
                f3.Show();         
            }
    
            private void GetForm2TextBox1Text(string s)
            {
                f3.textBox1.Text = s;
            }

    FORM2窗体代码

            public delegate void CallBack(string s);
            public event CallBack XYZ;
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                XYZ(textBox1.Text);
            }

    FORM3窗体代码

     无

    FORM1窗体代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
    
            Form2 f2 = new Form2();
            Form3 f3 = new Form3();
            private void Form1_Load(object sender, EventArgs e)
            {
                f2.XYZ += new Form2.CallBack(GetForm2TextBox1Text);
    
                f2.Dock = DockStyle.Fill;
                f2.TopLevel = false;
                f2.FormBorderStyle = FormBorderStyle.FixedToolWindow;
                f2.Parent = panel1;
                f2.Show();
    
                f3.Dock = DockStyle.Fill;
                f3.TopLevel = false;
                f3.FormBorderStyle = FormBorderStyle.FixedToolWindow;
                panel2.Controls.Add(f3);
                f3.Show();         
            }
    
            private void GetForm2TextBox1Text(string s)
            {
                f3.textBox1.Text = s;
            }
        }
    }
    View Code

    FORM2窗体代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
            
            public delegate void CallBack(string s);
            public event CallBack XYZ;
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                XYZ(textBox1.Text);
            }
        }
    }
    View Code

    FORM3窗体代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form3 : Form
        {
            public Form3()
            {
                InitializeComponent();
            }
        }
    }
    View Code
  • 相关阅读:
    makefile简单例子
    js归并排序
    js插入排序
    js堆排序
    js选择排序
    js冒泡算法以及优化
    使用go语言判断不同数据类型
    go使用接口案例排序
    go接口使用案例晓demo
    go面向对象-继承
  • 原文地址:https://www.cnblogs.com/xe2011/p/3440280.html