ShowDialog 的子窗体回传数据到父窗体
以前做B/S ,现在改C/S 方法不是很一样
Form1 里面
加入 set 访问器
string str_temp1;
public string str_test
{
set
{
str_temp1=value;
}
}
弹出Form2窗体
private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm2=new Form2();
frm2.Owner = this;
frm2.ShowDialog();
this.textBox1.Text=str_temp1;
}
Form2 窗体里面
private void button1_Click(object sender, System.EventArgs e)
{
if(this.textBox1.Text != "")
{
Form1 pfrm = (Form1)this.Owner;
pfrm.str_test = this.textBox1.Text;
this.Close();
}
else
{
MessageBox.Show("请输入!");
}
}
没有办法,好长时间没有接触WinForm了,以前只是用Delphi 作过一些WinForm 的程序
Form1 里面
加入 set 访问器
string str_temp1;
public string str_test
{
set
{
str_temp1=value;
}
}
弹出Form2窗体
private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm2=new Form2();
frm2.Owner = this;
frm2.ShowDialog();
this.textBox1.Text=str_temp1;
}
Form2 窗体里面
private void button1_Click(object sender, System.EventArgs e)
{
if(this.textBox1.Text != "")
{
Form1 pfrm = (Form1)this.Owner;
pfrm.str_test = this.textBox1.Text;
this.Close();
}
else
{
MessageBox.Show("请输入!");
}
}
没有办法,好长时间没有接触WinForm了,以前只是用Delphi 作过一些WinForm 的程序
 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号