点点人生

博客园 首页 联系 订阅 管理

1主窗体的代码:

namespace MyFirstApp
{
    public partial class Frm_main : Form
    {
        public Frm_main()
        {
            InitializeComponent();
        }

        public void DiaoYong(string str)
        {
            this.textBox1.Text = str;
        }


        private void button1_Click(object sender, EventArgs e)
        {
            string str = this.textBox1.Text;
            Frm_child f2 = new Frm_child(str);//在构造函数中,向子窗体传值。
            f2.Owner = this;
            f2.Show();

        }
    }
}

 

2,子窗体的代码

 

namespace MyFirstApp
{
    public partial class Frm_child : Form
    {
        public Frm_child(string ss)
        {
            InitializeComponent();
            this.textBox1.Text = ss;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string st = textBox1.Text;

            Frm_main f1;
            f1 = (Frm_main)this.Owner;
            f1.DiaoYong(st);
            this.Close();

        }
    }
}

posted on 2009-02-18 20:37  恋网小蚂蚁  阅读(510)  评论(0)    收藏  举报