码迷,mamicode.com
首页 > Windows程序 > 详细

C# MDI子窗体互相操作

时间:2016-07-30 11:56:34      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace WindowsFormsApplication1
12 {
13     public partial class Form1 : Form
14     {
15         private string name;
16         public Form1()
17         {
18             InitializeComponent();
19         }
20 
21         private void button1_Click(object sender, EventArgs e)
22         {
23             Form2 frm2 = new Form2();
24             frm2.MdiParent = this;
25             frm2.Show();
26         }
27 
28         private void button2_Click(object sender, EventArgs e)
29         {
30             Form3 frm1 = new Form3();
31             frm1.MdiParent = this;
32             frm1.Show();
33         }
34         public event Action<string> OnText;
35         public void ToChangeText(string obj)
36         {
37             if (OnText != null)
38             {
39                 OnText(obj);}
40         }
41         private void Form1_Load(object sender, EventArgs e)
42         {
43 
44         }
45     }
46 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace WindowsFormsApplication1
12 {
13     public partial class Form2 : Form
14     {
15         public Form2()
16         {
17             InitializeComponent();
18         }
19 
20         private void button1_Click(object sender, EventArgs e)
21         {
22             (this.ParentForm as Form1).ToChangeText("form2来的消息啊?");
23         }
24     }
25 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace WindowsFormsApplication1
12 {
13     public partial class Form3 : Form
14     {
15         public Form3()
16         {
17             InitializeComponent();
18         }
19 
20         private void Form3_Load(object sender, EventArgs e)
21         {
22             MessageBox.Show(this.ParentForm.Name);
23             (this.ParentForm as Form1).OnText += new Action<string>(Form3_OnText);
24         }
25         private void Form3_FormClosed(object sender, FormClosedEventArgs e)
26         {
27             (this.ParentForm as Form1).OnText -= new Action<string>(Form3_OnText);
28         }
29         void Form3_OnText(string obj)
30         {
31             textBox1.Text = textBox1.Text+obj;
32         }
33     }
34 }

 

C# MDI子窗体互相操作

标签:

原文地址:http://www.cnblogs.com/zhutiehan/p/5720403.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!