试图制作一个退出按钮

时间:2014-08-23 15:18:19

标签: vb.net button

我有一些我不确定的代码,我认为它适用于一个旧项目,但不确定我把它搞砸了。

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
    If MessageBox.Show("Are you sure?", MessageBox.Show(vbYesNo)) = Windows.Forms.DialogResult.No Then e.Cancel = True
End Sub

这是我的一个巨大错误:

Error   1   Overload resolution failed because no accessible 'Show' can be called without a narrowing conversion:
    'Public Shared Function Show(owner As System.Windows.Forms.IWin32Window, text As String) As System.Windows.Forms.DialogResult': Argument matching parameter 'owner' narrows from 'String' to 'System.Windows.Forms.IWin32Window'.
    'Public Shared Function Show(owner As System.Windows.Forms.IWin32Window, text As String) As System.Windows.Forms.DialogResult': Argument matching parameter 'text' narrows from 'System.Windows.Forms.DialogResult' to 'String'.
    'Public Shared Function Show(text As String, caption As String) As System.Windows.Forms.DialogResult': Argument matching parameter 'caption' narrows from 'System.Windows.Forms.DialogResult' to 'String'

1 个答案:

答案 0 :(得分:1)

为什么内部有MessageBox.Show(vbYesNo)而不只是vbYesNo

编辑:
减少snide:没有Show的重载,它接受一个字符串和一个DialogResult作为参数,也没有一个接受一个MsgBoxStyle参数。 也没有带有字符串和MsgBoxStyle常量的重载。 你可能意味着

MsgBox("Are you sure?", vbYesNo)

MessageBox.Show("Are you sure?", "Caption", MessageBoxButtons.YesNo)