【问题标题】:Yes/No function in a messagebox消息框中的是/否功能
【发布时间】:2020-10-13 21:53:12
【问题描述】:

我想在 InfoPath 2007 中的消息框(确定要退出吗?)中添加是/否功能。如果用户单击“是”,则 InfoPath 表单关闭,如果否,则用户被带走回到表格。根据我的阅读,这不会在 InfoPath 中发生。因此,我添加了一个带有是/否按钮的新窗口窗体。

对于“否”按钮,我有 (me.close) 关闭 windows 窗体,用户只剩下 InfoPath 窗体。当用户单击“是”表示他们想要关闭 Windows 表单和 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

【问题讨论】:

    标签: vb.net infopath


    【解决方案1】:
    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
    

    【讨论】:

    • 必须在主窗体上添加“Imports System.Windows.Forms”,但这有效。谢谢。
    【解决方案2】:

    以下是我解决这个问题的方法:

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

    【讨论】:

      【解决方案3】:
      If MessageBox.Show("Do you want to Exit?", "EXIT MESSAGE", MessageBoxButtons.YesNo) = DialogResult.Yes Then
          Me.Close()
      End If
      

      【讨论】:

        【解决方案4】:
        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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-01-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多