В VB.NET вы можете отобразить окно сообщения с кнопками «Да», «Нет» и «Отмена», используя класс MessageBox. Вот несколько методов, которые вы можете использовать:
-
Использование метода
MessageBox.Show:Dim result As DialogResult = MessageBox.Show("Message", "Title", MessageBoxButtons.YesNoCancel) If result = DialogResult.Yes Then ' Yes button clicked ' Perform corresponding action ElseIf result = DialogResult.No Then ' No button clicked ' Perform corresponding action ElseIf result = DialogResult.Cancel Then ' Cancel button clicked ' Perform corresponding action End If -
Использование перечисления
MessageBoxButtons:Dim result As DialogResult = MessageBox.Show("Message", "Title", MessageBoxButtons.YesNoCancel) Select Case result Case DialogResult.Yes ' Yes button clicked ' Perform corresponding action Case DialogResult.No ' No button clicked ' Perform corresponding action Case DialogResult.Cancel ' Cancel button clicked ' Perform corresponding action End Select -
Обработка нажатий кнопок с помощью обработчиков событий:
Private Sub ShowMessageBox() Dim messageBox As New MessageBox() AddHandler messageBox.YesButtonClicked, AddressOf YesButton_Clicked AddHandler messageBox.NoButtonClicked, AddressOf NoButton_Clicked AddHandler messageBox.CancelButtonClicked, AddressOf CancelButton_Clicked messageBox.Show("Message", "Title") End Sub Private Sub YesButton_Clicked(sender As Object, e As EventArgs) ' Yes button clicked ' Perform corresponding action End Sub Private Sub NoButton_Clicked(sender As Object, e As EventArgs) ' No button clicked ' Perform corresponding action End Sub Private Sub CancelButton_Clicked(sender As Object, e As EventArgs) ' Cancel button clicked ' Perform corresponding action End Sub