附件: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;
}
}
}

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

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

C# 动态创建出来的窗体间的通讯 delegate2的更多相关文章

  1. C# 动态创建出来的窗体间的通讯 delegate3

    附件1:http://files.cnblogs.com/xe2011/CSharp_WindowsForms_delegate03.rar 一个RTF文件管理器 描述 Form2,Form3,For ...

  2. C# 动态创建出来的窗体间的通讯 delegate1

    附件 http://files.cnblogs.com/xe2011/CSharp_WindowsForms_delegate01.rar 需要每个窗体是独立存在,禁止相与引用窗体 这样干净并且可以反 ...

  3. 自定义事件实现不同窗体间的通讯Delphi篇

    要实现子窗体与父窗体之间的通讯,有多种方法(比如:重载子窗体的构造函数,将父窗体的引用作为参数传递给子窗体).下面我要介绍的是利用自定义事件的方法,它能够最大程度的避免模块之间的耦合,充分体现面向对象 ...

  4. C#窗体间传值的简便方法/工具

    一.问题:窗体间传值必须需要窗体之间有联系,具体有如下方式 窗体间传值涉及到窗体A必须拥有窗体B,这样才可以实现A-B之间传值 窗体A与窗体B在窗体/实例C中,A-B可互相通讯 其他方式,不细讨论,复 ...

  5. C# 学习笔记(一) Winform利用Assembly反射动态创建窗体

    1. 添加Reflection //添加对Reflection程序集引用 using System.Reflection; // 引用窗体创建方法CreateForm,传入参数 private voi ...

  6. Delphi中动态创建窗体有四种方式

    Delphi中动态创建窗体有四种方式,最好的方式如下: 比如在第一个窗体中调用每二个,主为第一个,第二个设为动态创建 Uses Unit2; //引用单元文件 procedure TForm1.But ...

  7. c#反射动态创建窗体

    根据窗体的名称动态创建窗体 Assembly assembly = Assembly.GetExecutingAssembly();             // 实例化窗体 try { Form f ...

  8. DELPHI动态创建窗体

    //第一种方式 procedure TForm1.btn1Click(Sender: TObject); begin With TForm2.Create(Application) do Try Sh ...

  9. winform 用户控件、 动态创建添加控件、timer控件、控件联动

    用户控件: 相当于自定义的一个panel 里面可以放各种其他控件,并可以在后台一下调用整个此自定义控件. 使用方法:在项目上右键.添加.用户控件,之后用户控件的编辑与普通容器控件类似.如果要在后台往窗 ...

随机推荐

  1. android SurfaceView绘制 重新学习--切图clipRect详解

    解释都在代码注释中: public class SampleView extends View { private Paint mPaint; private Path mPath; public S ...

  2. 运维安全系列基础服务之 FTP 服务(系列一)

    做了多年运维工程师,积攒了一些经验,和大家分享下.个人认为,运维安全话题的系列,主要包括下面四个方面: 基础服务 网络层 应用层 云安全 今天主要讲的是基础服务里面的[FTP服务][ftp]. 文件传 ...

  3. http://www.cnblogs.com/xdp-gacl/p/4040019.html

    http://www.cnblogs.com/xdp-gacl/p/4040019.html

  4. WeakHashMap理解

    WeakHashMap实现了Map接口,是HashMap的一种实现,他使用弱引用作为内部数据的存储方案,WeakHashMap可以作为简单缓存表的解决方案,当系统内存不够的时候,垃圾收集器会自动的清除 ...

  5. VS2005 检测内存泄漏的方法(转载)

    一.非MFC程序可以用以下方法检测内存泄露: 1.程序开始包含如下定义: #ifdef _DEBUG #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __F ...

  6. 水平/竖直居中在旧版Safari上的bug

    今天调了两个出现在旧版Safari上的layout bug. 它们最初是在同事的iPad上被发现的, 我在自己桌面上安装的Safari 5.1.7上也能够复现. Bug1: .vertical-cen ...

  7. perl 对象

    唯一标识: 很明显,一个%employee 是不够的,每个雇员都要求有一个唯一标识和他或她自己的属性集合. 你可以动态的分配这个数据结构,也可以返回一个指向局部数据结构的引用 Vsftp:/root/ ...

  8. 如何实现Azure虚拟网络中点到站VPN的自动重连

     在Windows Azure早期版本中,用户要在某台Azure平台之外的机器与Azure平台内部的机器建立专用连接,可以借助Azure Connect这个功能.当前的Azure版本,已经没有Az ...

  9. ZOJ --- 3516 Tree of Three

    Tree of Three Time Limit: 2 Seconds      Memory Limit: 65536 KB Now we have a tree and some queries ...

  10. Monkey Test

    以前写的,可以在报错后抓Log. ::运行此脚本前,请确认手机是否已连接至PC且已开启Debug模式 @echo off REM 循环十次 set /a Num=0 :loop set /a Num+ ...