关闭子窗体时将子窗体的处理结果返回给父窗体,该怎么实现?

解决方案 »

  1.   

    http://community.csdn.net/Expert/topic/4724/4724247.xml?temp=.1744959
      

  2.   

    可以在子窗口中设置一个属性,比如用Ok按钮关闭子窗口,那么在Ok的事件中把计算结果写到这个属性里
    父窗口使用showdialog()调用子窗口
    class ChildForm : Form
    {
        Button btnOK;
        string Attr{ get{...;} set{...;}}
        
        private void btnOK_Click(object sender, EventArgs e)
            {
                this.Attr = result;
                this.DialogResult = DialogResult.OK;//这个让窗口关闭,并且返回OK结果;
            }
    }class ParentForm
    {
        string strParentAttr;
        ChildForm child = new ChildForm();
        .....
        if(child.ShowDialog() == DialogResult.OK)
        {
            this.strParentAttr = child.Attr;
        }
    }觉得这样看起来比在子窗体中放置父窗体的引用之类的方法看起来漂亮一些……
      

  3.   

    FunctionManageChildForm functionManageChildForm = new FunctionManageChildForm(this);
                functionManageChildForm.sNodeName = tvFunctionList.SelectedNode.Text;
                functionManageChildForm.sApplicationPath = RWXML.GetXmlFileValue(Configuration.getNodeFile(), getNodeKey());
                // 初始化功能管理画面的子画面
                functionManageChildForm.init("Modify", tvFunctionList.SelectedNode.Level, getNodeKey());            
                if (functionManageChildForm.ShowDialog() == DialogResult.OK)
                {
                    // 节点名称
                    sNodeName = functionManageChildForm.sNodeName;                // 应用软件的路径
                    sApplicationPath = functionManageChildForm.sApplicationPath;
                }