如何在windows应用程序关闭子窗口时刷新父窗口

问题描述:

我有一个父窗口和一个子窗口。在保存子窗口时,我收到了警告消息,然后按ok。按确定,我的孩子被关闭,父母被更新,但父窗体上的前一个对象仍然是他们的。 现在如何关闭旧版父页面[更新前]。如何在windows应用程序关闭子窗口时刷新父窗口

点击确定我需要返回更新的父页面。

结论:但我点击好的时候同时获得较旧的父窗口和新的父窗口。

上的OK代码点击如下:

Me.Close() 'for closing the child window.    
Dim frmparent As Form = New frmDomain 'for opening the parent window with updation. 
frmDomain2.StartPosition = FormStartPosition.CenterScreen 'to open it in center. 
frmDomain2.MdiParent = frmMain 
frmDomain2.Show() 

如果你打电话给你的窗口“子窗口”,那么你就不得不从“父窗口”称之。

如果我正确理解你的问题,从你内部调用你的chiled,把一个刷新函数在声明你的孩子的函数的末尾。即:

Dim FrmChild As Form = New ChildForm 
FrmChild .MdiParent = Me 
FrmChild.Show() 

call MyUpdateFormFunction() -- << this will be executed after FrmChild will be closed 

您更新父的方式取决于你打开你的子窗口的方式,模式或无模式:

  • 莫代尔:你的子窗口获得焦点和块家长。
    • 你必须使用childForm.ShowDialog()
    • 后,该行不会执行,直到子窗体关闭打开它。这意味着,你可以在ShowDialog()

这种方式后立即打电话给你的更新方法:

Public Sub SomeMethod() 
    'Code in the parent: 
    Dim childForm as New MyChildForm() 
    childForm.ShowDialog() 
    Me.UpdateParentMethod() 
    'other stuff the parent has to do 
End 
  • 无模式:你的子窗口不会阻止父。
    • 您可以使用child.Show()将孩子打开为非模态。
    • 在父项中,之后的行被执行,父项继续以正常方式运行。
    • 为了检测子表单何时关闭,您必须从父级订阅其OnFormClosed事件,并在那里执行您的refesh代码。

这样:

Public Sub SomeMethod() 
    Dim childForm as New MyChildForm() 
    AddHandler childForm.FormClosed, AddressOf ChildForm_FormClosed 
    childForm.Show() 
    'other stuff the parent has to do 
End 

Public Sub ChildForm_FormClosed(sender as Object, e as FormClosedEventArgs) 
    Me.UpdateParentMethod() 
End 

更多信息: