C# 实现弹出选择窗口并传回值

来源:互联网 发布:s白金剃刀数据 编辑:程序博客网 时间:2024/05/13 02:32

新建一个windows窗体 Form2 ,Form2里也有一个按钮和一个TextBox控件,在TextBox里输入你想要的返回值。
Form1里:

     private void button1_Click(object sender, EventArgs e)        {            Form2 f2 = new Form2();            f2.ShowDialog();            if (f2.DialogResult == DialogResult.OK)            {                this.textBox1.Text = f2.str;            }        }

Form2里:

 public  string str;        public  string Str         {            get { return this.str; }        } private void button1_Click(object sender, EventArgs e)        {            str = this.textBox1.Text;            this.DialogResult = DialogResult.OK;        }

这种是传值后Form2关闭的,还有一种是传值后Form2不关闭的。

0 0
原创粉丝点击