2010-09-08 59 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