日期:2014-05-18  浏览次数:20879 次

窗口的隐藏和显示问题
C# + winform环境。
在我的程序中通过点击某个菜单项打开一个窗口(frmCardGrant),然后在该窗口中点击一个名为btnTruckNoAdd的按钮,再打开另一个窗口(frmVehicleManage),但同时要隐藏掉frmCardGrant窗口使其不可见。当frmVehicleManage窗口操作完毕关闭时,又需要显现原来的那个窗口(frmCardGrant)。现在我已经可以实现在打开frmVehicleManage窗口的同时隐藏frmCardGrant窗口(代码如下),但不知道如何在关闭frmVehicleManage后再显现frmCardGrant,特请教各位。谢谢!

private void btnTruckNoAdd_Click(object sender, EventArgs e)
  {
  Type type = null;
  type = typeof(frmVehicleManage);
  Form subForm = null;
  subForm = (Form)Activator.CreateInstance(type);
  subForm.MdiParent = this.ParentForm;
  this.Hide(); //关闭原窗口
  subForm.Show();
  subForm.Update(); //显示新窗口
   


}

------解决方案--------------------
C# code
打开的frmVehicleManage的事件
frmVehicleManage frm=new frmVehicleManage();
    if (frm.ShowDialog() == DialogResult.OK)
                {
                    this.show();
                }

frmVehicleManage 的关闭事件中
this.DialogResult = DialogResult.OK;

------解决方案--------------------
C# code

            this.Hide();
            Form2 frm = new Form2();
            if (frm.ShowDialog() == DialogResult.OK)
            {
                this.Show();
            }