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:
There is no Critical
icon on the message box.
How can I do this?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With