Matt Matt - 6 months ago 44
Vb.net Question

Combine two MsgBoxStyles in one with VB.NET

I'm trying to create a

MsgBox()
that has both the
MsgBoxStyle.Critical
style and the
MsgBoxStyle.RetryCancel
button style. What I've tried so far is this:



Private Sub DoSomething()
Dim Answer as MsgBoxResult
Answer = MsgBox("Error", MsgBoxStyle.RetryCancel & MsgBoxStyle.Critical, _
"Some sort of error.")
If Answer = MsgBoxResult.Retry Then
'REM: Try code again
Elseif Answer = MsgBoxResult.Cancel Then
Exit Sub
End If
End Sub


This is what the buttons currently look like:

Should be Retry/Cancel

There is no
Critical
icon on the message box.

How can I do this?

Answer

Use MessageBox instead of MsgBox. Try this:

    Dim _result As DialogResult = MessageBox.Show("Do you want to retry", "Confirm Retry", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error)
    If _result = Windows.Forms.DialogResult.Retry Then
        ' try again code
    Else

    End If

MessageBox Sample