這應該很簡單,但我無法使其工作。我搜索了SO和Google,令人驚訝的是我還沒有找到答案。當另一個表格關閉時,我想要做的就是關閉一個表單。第二種形式是在點擊按鈕時打開。當Form1關閉時,Form2也應該關閉。 Form2可能無法打開,因此我們需要檢查它是否首先打開。這是我一直在努力:當另一個窗體關閉時關閉窗體
Private Sub frm_scu_config_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
' this isn't working
If Application.OpenForms().OfType(Of frm_scu_report_display).Any Then
Dim frmConfig As frm_scu_report_display
' Open the config form and pass the list of turbines
frmConfig = New frm_scu_report_display()
frmConfig.Close()
End If
End Sub
任何幫助,將不勝感激。
'如果Form2的狀態並沒有沒有那麼Form2.Close' – Plutonix
使用布爾變量作爲標誌.. – matzone
謝謝@Plutonix。如果我在if語句中拋出一個消息框,它會正確識別第二個表單是否打開,但它不會關閉它。 – mack