我想在允許模式框關閉之前驗證一些數據,但它在驗證發生之前似乎關閉。這是我的代碼如何中止模式框關閉?
Public Class my_popup
Inherits Form
Dim result = Me.ShowDialog()
If result = DialogResult.OK Then
If key = Nothing Then
If last_name.Text <> "" Then
MessageBox.Show("The user is not in the database.")
' Abort closing and leave dialog open.
End If
Else
save_it()
End If
End If
End Class
當消息框出現時,模態窗體已經關閉。我如何避免這種情況發生?
_Me.ShowDialog()_?你在哪種方法中調用這個方法? – Steve
我編輯它以顯示課程。 – user2721815
您只是將MessageBox.Show()調用放在了錯誤的位置。它只能在關閉對話框後運行*。把它放在它所屬的地方,在確定按鈕中單擊事件處理程序。不滿意時不要設置DialogResult屬性。 –