在C#中,发生异常时MessageBox.Show(ex.Message)
在C#中,发生异常时MessageBox.Show(ex.Message)弹出异常对话框,如何自动关闭该异常对话框?万分感谢!...
在C#中,发生异常时MessageBox.Show(ex.Message)弹出异常对话框,如何自动关闭该异常对话框?万分感谢!
展开
5个回答
展开全部
这个很简单哦,可以自己写一个窗体来代替Messagebox:
1 新建一个窗体
2 拖一个timer
3 放一个ok按钮,一个取消按钮
4 重点是timer的运行代码
-----------主要代码有:
Public Class OpDialog
#Region "字段"
''' <summary>
''' 这个是设置显示多少秒,然后会自动关闭的
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property DisplaySeconds As Integer
Get
Return OpDialog._seconds
End Get
Set(ByVal value As Integer)
If value >= 2 Then
_seconds = value
End If
End Set
End Property
Private Shared _seconds As Integer = 0
#End Region
'设置ok和取消按钮的事件,就可以手动点击
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
Private Sub OpDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblMsg.Text = My.MySettings.Default.OpDialogSeconds.ToString()
_seconds = My.MySettings.Default.OpDialogSeconds
Me.Timer1.Enabled = True
Me.Timer1.Interval = 1000
End Sub
'-------------这里是timer的运行代码,很简单吧,每tick一次把时间减去1秒
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If _seconds <= 0 Then
Me.Timer1.Enabled = False
CType(Me.ActiveControl, Button).PerformClick()
End If
_seconds -= 1
lblMsg.Text = (_seconds).ToString()
End Sub
End Class
1 新建一个窗体
2 拖一个timer
3 放一个ok按钮,一个取消按钮
4 重点是timer的运行代码
-----------主要代码有:
Public Class OpDialog
#Region "字段"
''' <summary>
''' 这个是设置显示多少秒,然后会自动关闭的
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property DisplaySeconds As Integer
Get
Return OpDialog._seconds
End Get
Set(ByVal value As Integer)
If value >= 2 Then
_seconds = value
End If
End Set
End Property
Private Shared _seconds As Integer = 0
#End Region
'设置ok和取消按钮的事件,就可以手动点击
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
Private Sub OpDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblMsg.Text = My.MySettings.Default.OpDialogSeconds.ToString()
_seconds = My.MySettings.Default.OpDialogSeconds
Me.Timer1.Enabled = True
Me.Timer1.Interval = 1000
End Sub
'-------------这里是timer的运行代码,很简单吧,每tick一次把时间减去1秒
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If _seconds <= 0 Then
Me.Timer1.Enabled = False
CType(Me.ActiveControl, Button).PerformClick()
End If
_seconds -= 1
lblMsg.Text = (_seconds).ToString()
End Sub
End Class
展开全部
自己写一个类似的form,load后计时并调close关闭。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
重载 ,自定义关闭方式.
追问
如何做?谢谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
自动关闭?那你就不要弹出不行嘛?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询