Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 809
Matt Avatar asked Dec 12 '22 00:12

Matt


2 Answers

Bitwise "combine" is called Or.

MsgBoxStyle.RetryCancel Or MsgBoxStyle.Critical

MsgBoxStyle.RetryCancel & MsgBoxStyle.Critical evaluates to "5" + "16", which evaluates to "516", which evaluates to 516, which magically equals MsgBoxStyle.YesNo Or MsgBoxStyle.DefaultButton3 and is therefore interpreted as such.

Don't use the string concatenation operator & for bitwise logic.

like image 175
GSerg Avatar answered Dec 14 '22 14:12

GSerg


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

like image 45
Ambrose Avatar answered Dec 14 '22 12:12

Ambrose