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 里面可以放各种其他控件,并可以在后台一下调用整个此自定义控件. 使用方法:在项目上右键.添加.用户控件,之后用户控件的编辑与普通容器控件类似.如果要在后台往窗 ...
随机推荐
- 写一个TT模板自动生成spring.net下面的配置文件。
这个是目标. 然后想着就怎么开始 1.
- XCode 项目配置说明
初学XCode最让人头疼的就是项目各属性设置,各种不解,这里做个总结: 项目配置: 基本项(Basic) 1.Architectures(指令集)——设置你想支持的指令集,目前ios的指令集有以下几种 ...
- SQL Join PK ChinaJoy
P PK
- 听同事讲 Bayesian statistics: Part 2 - Bayesian inference
听同事讲 Bayesian statistics: Part 2 - Bayesian inference 摘要:每天坐地铁上班是一件很辛苦的事,需要早起不说,如果早上开会又赶上地铁晚点,更是让人火烧 ...
- textarea宽度、高度自动适应处理方法
textarea自动高度 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http: ...
- Colored Sticks
poj2513:http://poj.org/problem?id=2513 题意:就是求一个欧拉回路. 题解:本题是判断欧拉通路是否存在,但是如果是用map的话就会超时,这里采用了trie树,有发现 ...
- Eclipse怎样导入github上的项目
国外有些比较好的源代码网站,经常需要从这些网站上导入项目到eclipse中,我最近就发现github.com这个网站上有很多开源项目.这里就以从github网站上导入项目到eclipse中为例来详细的 ...
- greenDaoMaster的学习研究
最近一直在研究一个第三方的开源框架,greenDaoMaster是一个移动开发的ORM框架,由于网上一直查不到使用资料,所以自己摸索总结下用法. 首先需要新建一个JAVA项目用来自动生成文件.需要导入 ...
- 匿名hash
[root@oadb test]# cat a1.pl use Data::Dumper; my @a=qw/1 3 5 7 9/; push @b ,{@a}; print Dumper(@b); ...
- perl post json数据
use LWP::UserAgent; use URI::Escape; use Net::Ping; use JSON qw(encode_json); use Socket; use Net::S ...