新的空间

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

创建两个窗体Form1和Form2,在两个窗体中分别创建textBox1和Button1,Form2中的Button1的DialogResult设置为OK,现在创建事件如下所示:

Form1中的button1事件

 1        private void button1_Click(object sender, EventArgs e)
 2        {
 3            Form2 frm2 = new Form2();
 4            frm2.Form2_Load(textBox1.Text);
 5            frm2.ShowDialog();
 6            if (frm2.DialogResult == DialogResult.OK)
 7            {
 8                textBox1.Text = frm2.info;
 9            }

10        }

Form2中的button1事件和From_load事件

 1        public Form2()
 2        {
 3            InitializeComponent();
 4        }

 5        public string info
 6        {
 7            get
 8            {
 9                return textBox1.Text;
10            }

11        }

12
13        internal void Form2_Load(string info)
14
15        {
16            textBox1.Text = info;
17        }

18
19        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
20        {
21            DialogResult = DialogResult.OK;
22        }

演示效果描述:

在Form1中textBox1输入xumng.cnbologs.com点击button1,打开窗体Form2,Form2中的textBox1的已经填上xumng.cnblogs.com,修改Form2中的textBox1的值为http://xumng.cnblogs.com,点击Form2中的按钮,窗口关闭后将值传递给Form1中的textBox1。
posted on 2006-06-17 19:14  旭萌  阅读(442)  评论(0编辑  收藏  举报