特定のフォームが閉じると、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