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
  • 相关阅读:
    identityser4 samesit 问题
    mysql 8 root密码重置
    OutSystems学习笔记。
    获取两个List中的不同元素,4种方法,逐步优化,学习使用
    java 配置在.properties文件中的常量
    java POST 传值 加签 验证
    springboot jpa 多条件查询(多表)
    java代码行数统计工具类
    Map集合遍历的4种方法
    springboot jpa 多条件查询(单表)
  • 原文地址:https://www.cnblogs.com/xe2011/p/3440280.html
Copyright © 2011-2022 走看看