Search code examples
vb.netcompact-framework

MesageBox Show only accepts two arguments, but I need a third argument


I need to have a confirmation dialog box by showing MessageBox.Show("Caption", "Title", MessageBoxDialog), but an error occurred "Error 1 Overload resolution failed because no accessible 'Show' accepts this number of arguments"

Already tried to check some other codes in the internet, but its always with the same error.

This was copied from dotnetperls.com

`   Dim result1 As DialogResult = MessageBox.Show("Is Dot Net Perls awesome?", "Important Question", MessageBoxButtons.YesNo)`

and this one is currently in my code, copied from MessageBox with YesNoCancel - No & Cancel triggers same event

 `Dim result As Integer = MessageBox.Show("message", "caption", MessageBoxButtons.YesNoCancel)
    If result = DialogResult.Cancel Then
        MessageBox.Show("Cancel pressed")
    ElseIf result = DialogResult.No Then
        MessageBox.Show("No pressed")
    ElseIf result = DialogResult.Yes Then
        MessageBox.Show("Yes pressed")
    End If`

Solution

  • Variant 1

    
    Dim result = MsgBox("Message" , MsgBoxStyle.YesNoCancel, "Caption")
    Select Case result
        Case MsgBoxResult.Yes
          MsgBox("Yes pressed")   
        Case MsgBoxResult.No
          MsgBox("No pressed")   
        Case MsgBoxResult.Cancel
          MsgBox("Cancel pressed")   
    End Select
    

    Variant 2

    Dim result = MessageBox.Show("Message", "Caption", MessageBoxButtons.YesNoCancel)
    If result = DialogResult.Cancel Then
        MessageBox.Show("Cancel pressed")    
    ElseIf result = DialogResult.No Then
        MessageBox.Show("No pressed")    
    Else
        MessageBox.Show("Yes pressed")    
    End If