窗口间传值

 1 namespace 窗体间传值
 2 {
 3     public partial class Form1 : Form
 4     {
 5         public Form1()
 6         {
 7             InitializeComponent();//初始化
 8             Form2 f2 = new Form2();//实例化FORM2
 9             f2.send += delegate( string[] text )//订阅f2的事件send,并以匿名方法处理
10             {
11                 string t = "";
12                 foreach ( var item in text )
13                 {
14                     t += item;
15                 }
16                 textBoxForm1.Text = t;
17             };
18             f2.Show();
19         }
20     }
21     
22     public partial class Form2 : Form
23     {
24         public Form2()
25         {
26             InitializeComponent();
27             btnSend.Click += new EventHandler(btnSend_Click);//点击事件及处理
28         }
29         public delegate void sendStr( string[] data );//委托类型声明
30         public event sendStr send;//事件声明
31         private void btnSend_Click( object sender , EventArgs e )//触发事件
32         {
33             string[] ss = textBoxForm2.Text.Split(',');
34             send( ss );//将ss附加到事件
35         }
36         
37         
38     }
39 }

 

posted @ 2017-07-28 01:50  xiogun  阅读(136)  评论(0)    收藏  举报