父窗口调用子窗口,关闭子窗口将内容返回给父窗口
//父窗口调子窗口函数
private void ShowLinkDBDialog(object sender, EventArgs e)
{
//连接子对话框。
fchild obj = new fchild(this);//this父窗口
obj.WindowState = FormWindowState.Normal;
obj.ShowDialog();
this.TextBox1.Text = obj.RetValue;
}
子窗口相关内容
private Form _parentForm=null;
private static string _RetValue = null;
public string RetValue
{
get { return _RetValue; }
}
//
public fVistSQLServer(Form parentForm)//带参数的构造函数
{
InitializeComponent();
this._parentForm = parentForm;
}
//点确定按钮,返回信息到父窗口,并关闭子窗口.
private void confirm_Click(object sender, EventArgs e)
{
_RetValue = this.TextBox1.Text.Trim();
//((fparent)_parentForm).TextBox2.Text="123";
//关闭窗口
this.Close();
}