vb表单按钮控件

时间:2010-09-08 17:25:30

标签: vb.net forms button

非常基本的问题。我有3个表格。一个带有两个按钮的主窗体,需要在单击按钮时打开另外两个窗体中的一个。现在当点击按钮2然后表格2应该打开并且表格形式2人应该可以点击返回并进入主表格。 我怎么能这样做?

2 个答案:

答案 0 :(得分: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()

答案 1 :(得分:0)

在调用表单中,声明对被调用表单的引用,如果要捕获表单的事件(如form_closing),则使用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

然后您可以处理第二个表单的onclosing事件:

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