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;
}
}
}
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的更多相关文章
- C# 动态创建出来的窗体间的通讯 delegate3
附件1:http://files.cnblogs.com/xe2011/CSharp_WindowsForms_delegate03.rar 一个RTF文件管理器 描述 Form2,Form3,For ...
- C# 动态创建出来的窗体间的通讯 delegate1
附件 http://files.cnblogs.com/xe2011/CSharp_WindowsForms_delegate01.rar 需要每个窗体是独立存在,禁止相与引用窗体 这样干净并且可以反 ...
- 自定义事件实现不同窗体间的通讯Delphi篇
要实现子窗体与父窗体之间的通讯,有多种方法(比如:重载子窗体的构造函数,将父窗体的引用作为参数传递给子窗体).下面我要介绍的是利用自定义事件的方法,它能够最大程度的避免模块之间的耦合,充分体现面向对象 ...
- C#窗体间传值的简便方法/工具
一.问题:窗体间传值必须需要窗体之间有联系,具体有如下方式 窗体间传值涉及到窗体A必须拥有窗体B,这样才可以实现A-B之间传值 窗体A与窗体B在窗体/实例C中,A-B可互相通讯 其他方式,不细讨论,复 ...
- C# 学习笔记(一) Winform利用Assembly反射动态创建窗体
1. 添加Reflection //添加对Reflection程序集引用 using System.Reflection; // 引用窗体创建方法CreateForm,传入参数 private voi ...
- Delphi中动态创建窗体有四种方式
Delphi中动态创建窗体有四种方式,最好的方式如下: 比如在第一个窗体中调用每二个,主为第一个,第二个设为动态创建 Uses Unit2; //引用单元文件 procedure TForm1.But ...
- c#反射动态创建窗体
根据窗体的名称动态创建窗体 Assembly assembly = Assembly.GetExecutingAssembly(); // 实例化窗体 try { Form f ...
- DELPHI动态创建窗体
//第一种方式 procedure TForm1.btn1Click(Sender: TObject); begin With TForm2.Create(Application) do Try Sh ...
- winform 用户控件、 动态创建添加控件、timer控件、控件联动
用户控件: 相当于自定义的一个panel 里面可以放各种其他控件,并可以在后台一下调用整个此自定义控件. 使用方法:在项目上右键.添加.用户控件,之后用户控件的编辑与普通容器控件类似.如果要在后台往窗 ...
随机推荐
- ie8下jquery读取当前点击的标签位置错误,原因是里面有内容写了text-indent:-9999px
今天写一地图的效果,鼠标点击对应的区域,弹出所点击区域的名字. 因为设计的区域名字有特殊效果,所以,在点击区域里面套了个标签写上区域名字用来识别,但是这个文字呢不同显示在页面上,所以就给 em 加个了 ...
- Web应用的组件化(一)
基本思路 1. 为什么要做组件化? 无论前端也好,后端也好,都是整个软件体系的一部分.软件产品也是产品,它的研发过程也必然是有其目的.绝大多数软件产品是追逐利润的,在产品目标确定的情况下,成本有两个途 ...
- 【技术贴】note8 N5100刷机 双清 落雨
双清模式:开机键 + [音量+] + HOME键 刷机模式:开机键 + [音量- ]+ HOME键 1.双清步骤: 关机时.长按音量上键+home键+开机键,直到进入recovery模式,然后选择wi ...
- angular2 学习笔记 ( Router 路由 )
参考 : https://angular.cn/docs/ts/latest/guide/router.html#!#can-activate-guard https://angular.cn/doc ...
- PYTHON之DEF
def sayHello(): print('Hello World!') while True: s = input('Enter something : ') if s == 'quit': br ...
- 设计模式之策略模式Strategy
/** * 策略设计模式 * 策略模式:定义一系列的算法族,使他们之间可以相互转换,动态的改变其行为. * 问题:设计一个鸭子模拟游戏. * 现在有一群鸭子: * ①这些鸭可以有飞的行为(分为快和慢) ...
- Jquery UI dialog 传参
[一篮饭特稀原创,转载请注明出自http://www.cnblogs.com/wanghafan/p/3519318.html] $("#dialog").dialog({ aut ...
- pcDuino汉化方法
1,打开终端:2,在终端输入命令 sudo apt-get update 更新一下软件源3, 输入命令下载中文支持包 sudo apt-get install language-pack-gnome- ...
- 织梦内容管理系统(DedeCms) 小说模块insert注入漏洞
漏洞版本: Dedecms 漏洞描述: DedeCms是免费的PHP网站内容管理系统. 织梦内容管理系统(DedeCms) 以简单.实用.开源而闻名,是国内最知名的PHP开源网站管理系统,也是使用用户 ...
- HDU 5963 朋友 【博弈论】 (2016年中国大学生程序设计竞赛(合肥))
朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Descr ...