1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
using
System.Windows.Forms;
namespace
窗体间通信
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
Form2 f2=
new
Form2();
f2.send +=
delegate
(
string
text)
{
//订阅f2的事件send,并以匿名方法处理
textBoxForm1.Text = text;
};
f2.Show();
}
}
}
|
/""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
using
System;
using
System.Windows.Forms;
namespace
窗体间通信
{
public
partial
class
Form2 : Form
{
public
Form2()
{
InitializeComponent();
}
public
delegate
void
sendStr(
string
data);
//委托类型声明
public
event
sendStr send;
//事件声明
private
void
btnSend_Click(
object
sender, EventArgs e)
{
send(textBoxForm2.Text);
//触发事件
}
}
}
|