窗体一:

View Code
 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 ChuangTi
12 {
13     public partial class frmHomework : Form
14     {
15         public frmHomework()
16         {
17             InitializeComponent();
18         }
19         frmAnser myfA = null;
20         private void btnPL_Click(object sender, EventArgs e)
21         {
22             if (myfA == null||myfA.IsDisposed==true)
23             {
24                 myfA = new frmAnser(txtIn.Text);//传值一种方法 (构造函数)
25             }
26             else
27             {
28                 myfA.GetAnser = txtIn.Text; //传值的第二种方法(属性访问器)
29             }
30             myfA.Show();
31         }
32 
33         private void btnSend2_Click(object sender, EventArgs e)
34         {
35             if (myfA == null || myfA.IsDisposed == true)
36             {
37                 myfA = new frmAnser(txtIn.Text);//这里没什么作用,只是为了迎合第一种方法
38                 myfA.Tag = txtIn.Text;//传值的第三种方法(Tag,所有继承Control的都有Tag属性,Tag是object类型,可以放任何东西,但取得时候要转换)
39             }
40             else
41             {
42                 myfA.GetAnser = txtIn.Text;
43             }
44             myfA.Show();
45         }
46 
47         private void btnSend3_Click(object sender, EventArgs e)
48         {
49 
50         }
51 
52         private void btnSend4_Click(object sender, EventArgs e)
53         {
54 
55         }
56     }
57 }

窗体二:

View Code
 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 ChuangTi
12 {
13     public partial class frmAnser : Form
14     {
15         public frmAnser(string txt)
16         {
17             InitializeComponent();
18             lbAnser.Text = txt;
19             if (this.Tag != null)
20             {
21                 lbAnser.Text = (String)Tag;
22             }
23         }
24 
25         private void frmAnser_Load(object sender, EventArgs e)
26         {
27 
28         }
29         public string GetAnser
30         {
31             set 
32             { 
33                 this.lbAnser.Text=value;
34             }
35         }
36     }
37 }

 

posted on 2012-12-10 22:39  陈谨  阅读(162)  评论(0编辑  收藏  举报