【发布时间】:2011-04-09 21:04:41
【问题描述】:
非常基本的问题。我有 3 个表格。一个带有两个按钮的主窗体,需要在单击按钮时打开另外两个窗体之一。现在,当单击按钮 2 时,应该打开表单 2,并且表单 2 的人应该能够单击返回并进入主表单。 我该怎么做?
【问题讨论】:
非常基本的问题。我有 3 个表格。一个带有两个按钮的主窗体,需要在单击按钮时打开另外两个窗体之一。现在,当单击按钮 2 时,应该打开表单 2,并且表单 2 的人应该能够单击返回并进入主表单。 我该怎么做?
【问题讨论】:
在调用表单中,声明对被调用表单的引用,如果要捕获表单的事件(如 form_closure),请使用 withevents 关键字
Public Class MDIMain
Private WithEvents _cases As frmGrid
然后,当他们点击某些东西以打开第二个表单时,创建它的一个新实例:
Private Sub mnuViewCaseFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewCaseFiles.Click
If IsNothing(_cases) Then
_cases = New frmGrid
_cases.WindowState = FormWindowState.Maximized
End If
_cases.Visible = Me.mnuViewCaseFiles.Checked
End Sub
然后你可以处理第二个表单的关闭事件:
Private Sub _cases_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles _cases.FormClosing
_cases = Nothing
mnuViewCaseFiles.Checked = False
End Sub
【讨论】:
VB 有点模糊,但这应该足够好了:)
On click of button that shows form2 [Modified]
Dim frmOne as Form1
frmOne = Me
Dim frmTwo as Form2
frmTwo = new Form2(frmOne)
frmTwo.show()
Note: Form2 should have a constructor that takes form1 object.
To come back place a button on Form2 and pass the object of first form to form2.
me.hide() or me.visible = false
frmOne.show()
【讨论】: