消息框中的是/否功能

时间:2012-02-07 18:02:02

标签: vb.net infopath

我想在InfoPath 2007中的消息框中添加“是/否”功能(确定要退出吗?)。如果用户单击“是”,InfoPath表单将关闭,如果不是,则用户将被删除回到表格。从我所看到的,这不会发生在InfoPath中。所以,我添加了一个带有Yes / No按钮的新窗体。

对于“否”按钮,我(me.close)关闭了窗体,用户留下了InfoPath窗体。当用户单击“是”时,我需要帮助,这意味着他们要关闭窗体和InfoPath表单。以下是我的代码。非常感谢提前。

Imports Microsoft.Office.InfoPath 
Imports System 
Imports System.Xml 
Imports System.Xml.XPath 
Imports System.Diagnostics

Public Class Confirm_Close 
Private Sub btnNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNo.Click 

Me.Close() 

End Sub 

Private Sub btnYes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYes.Click 

Try 

<need help here>

Catch ex As Exception 

Console.WriteLine(ex.Message) 

End Try 

End Sub 

End Class

4 个答案:

答案 0 :(得分:4)

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

    If MessageBox.Show("Do you want to exit?", "Title", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then

        Me.Close()

    End If

End Sub

答案 1 :(得分:2)

以下是我如何解决这个问题:

If MsgBox("Prompt", MsgBoxStyle.YesNoCancel, "Title") = MsgBoxResult.Yes Then
    ' execute command
End If

答案 2 :(得分:0)

If MessageBox.Show("Do you want to Exit?", "EXIT MESSAGE", MessageBoxButtons.YesNo) = DialogResult.Yes Then
    Me.Close()
End If

答案 3 :(得分:0)

Dim result = MessageBox.Show("Are you sure you want to close?", "are you sure?", MessageBoxButtons.YesNoCancel)
    If result = DialogResult.Yes Then
        Me.Close()
    End If
End Sub