【问题标题】:MesageBox Show only accepts two arguments, but I need a third argumentMessageBox Show 只接受两个参数,但我需要第三个参数
【发布时间】:2019-10-04 11:00:28
【问题描述】:

我需要通过显示 MessageBox.Show("Caption", "Title", MessageBoxDialog) 来获得一个确认对话框,但发生错误“错误 1 ​​重载解析失败,因为没有可访问的 'Show' 接受此数量的参数”

已经尝试检查互联网上的一些其他代码,但总是出现相同的错误。

这是从 dotnetperls.com 复制的

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

这个目前在我的代码中,复制自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`

【问题讨论】:

  • 您使用的是什么版本的 .net?
  • 我怀疑您的项目中有一个名为MessageBox 的类。这将优先于引用程序集中具有相同名称的类型。更改该名称或限定代码中的其他类型。
  • 我建议在该代码中使用Select Case。会比If...ElseIf更简洁。
  • 尝试像这样使用它System.Windows.Forms.MessqgeBox.Show()
  • 如果你想要另一个论点,你来对地方了 =)

标签: vb.net compact-framework


【解决方案1】:

变体 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

变体 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

【讨论】:

    【解决方案2】:

    从我之前认为丢失的代码中:

    If confirm = MsgBoxResult.Yes Then Dim reConfirm As MsgBoxResult = MsgBox("YOU ARE REALLY SURE?", MsgBoxStyle.YesNo) If reConfirm = MsgBoxResult.Yes Then End If End If

    【讨论】:

      猜你喜欢
      • 2018-06-09
      • 1970-01-01
      • 2014-12-13
      • 2023-03-19
      • 1970-01-01
      • 2023-03-23
      • 2011-09-13
      • 1970-01-01
      • 2013-07-29
      相关资源
      最近更新 更多