当某个表单关闭时,我会捕获该formClosing
事件以检查用户是否真的想要关闭它。
但是,如果单击“下一步>”,我不希望执行此检查,除非我知道检查了哪个按钮,否则总是寻求构象。
有没有办法可以将用户单击的按钮传递给confirm_exit()
函数,这样如果它是“下一步>”我可以忽略检查并重新运行“False”?
'*'
' Carries out actions when the user clicks the 'X' button to close the form
'*'
Private Sub btnX(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Dim clicked As Button ' The button that the user clicked
clicked = ??? ' How do I get the button that was last clicked?
e.Cancel = confirm_exit(clicked)
End Sub
'**
' Checks that the user does actually want to cancel the Music Renamer
'*
Public Function confirm_exit(Optional clicked As Button = Nothing) As Boolean
' Ask the user if they are sure that they wish to cancel the Music Renamer
Dim cancel As String = MsgBox("The Music Renamer is not finished yet. Are you sure you wish to quit?", vbYesNo, "Are you sure?")
' Set confirm_exit to false by default
confirm_exit = False
' Check if the user clicked 'Next >', and exit the function if they did
If clicked.Name = "btnNext" Then Exit Function
' If the user is sure, close the Music Renamer form
If Not cancel = vbYes Then confirm_exit = True
End Function