我有一个父窗口和一个子窗口。在保存子窗口时,我收到警告消息,然后按下确定。按下确定我的孩子关闭,父母得到更新但父母表格上的前一个对象仍然是他们的。 现在,如何关闭较旧的父页面[更新前]。
点击确定后,我只需要返回更新的父页面。
结论:但是,点击确定,我得到了较旧的父窗口和新的父窗口。
单击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()
答案 0 :(得分:1)
更新父级的方式取决于打开子窗口,模态或无模式的方式:
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()
将孩子打开为无模式。这样:
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
更多信息:
答案 1 :(得分:0)
如果您将窗口称为"子窗口",则必须从父窗口调用它"。
如果我正确地理解了您的问题,请在您称之为chiled的内部,在您声明孩子的函数的末尾放置一个刷新函数。即:
Dim FrmChild As Form = New ChildForm
FrmChild .MdiParent = Me
FrmChild.Show()
call MyUpdateFormFunction() -- << this will be executed after FrmChild will be closed