0

hi i have a vb application with two forms. With Form A I can start Form B and Form A is then visible=false. If I click on the red "X" on the right corner I want that form B close and Form A is visible true.

How I can do this?

4

2 回答 2

4

您可以在 FormB 中设置如下内容:

Private objFromForm As FormA

Sub New(FromForm As FormA)
    InitializeComponent()
    objFromForm = FromForm
End Sub

Private Sub FormB_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    objFromForm.Visible = True
End Sub

基本上,当 FormA 调用 FormB 的构造函数时,它会传递对自身的引用。然后,在 FormB 的“FormClosing”事件中,您可以使用该引用使 FormA 在 FormB 关闭之前再次可见。这是 FormA 方面的一个示例,带有一个按钮,该按钮使 FormB 的新实例可见并将对自身 (FormA) 的引用传递给 FormB 构造函数:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim objNewForm As New FormB(Me)
    objNewForm.Show()
    Me.Visible = False
End Sub
于 2013-11-01T13:08:49.980 回答
3

基本上你可以这样做..

调用 FormB 时 FormA

Me.Visible = False
FormB.Showdialog

在 FormB FormClosing 事件中

FormA.Visible = True
于 2013-11-01T13:12:40.273 回答