2010-09-08 58 views
0

非常基本的问题。我有3种形式。一个带有两个按钮的主窗体,需要在单击按钮时打开其他两种窗体中的一种。现在当说按钮2被点击时,表格2应该打开,并且也就是表格2的人应该可以点击返回到主表格。 我该怎么做?vb表单按钮控件

回答

0

有些模糊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() 
0

在调用的形式,宣布向被叫形式的参考,如果你想陷阱形式的事件(使用WithEvents关键字像form_closing)

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