在我的程序(form1)中,我用Form3.ShowDialog()调用另一个表单(form3)。此表单运行一个相对较长的进程,由进度条跟踪。在这种形式中,有一个按钮来取消这个过程(生成pdf文档)并还原这个过程。
取消按钮(form3)的代码如下:
Private Sub annulerBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles annulerBtn.Click
If (MsgBox("Êtes-vous sûr de vouloir annuler? Cette reviendra toutes les modifications apportées au document", MsgBoxStyle.YesNo, "annuler l'exportation") = MsgBoxResult.Yes) Then
_cancel = True
doc.Close() 'close pdf'
fs.Close() 'close stream'
If (_done And _backup) Or (Not _done And _backup) Then
'revert file from backup if backup exists'
System.IO.File.Delete(_path)
IO.File.Copy("C:\temp\temp.pdf", _path)
IO.File.Delete("C:\temp\temp.pdf")
Else
'otherwise simply delete the new file'
System.IO.File.Delete(_path)
End If
Me.Close()
Else
'continue with the form!!'
End If
End Sub我希望这个按钮结束进程并使用备份还原更改。
我目前远离多线程和im,在进程中使用Application.DoEvents()继续接收用户输入。
如果用户按下“是”按钮,该函数将按预期工作。但是,如果用户按下否,该过程将按预期继续进行,但表单将在之后关闭!
调试表明,它从不在用户按no之后调用Me.Close()或Form3.Close()。
对此问题的任何帮助都将不胜感激,谢谢!
编辑:这里是调用堆栈
App58.exe!App58.Form3.Form3_FormClosing(Object sender = {App58.Form3}, System.Windows.Forms.FormClosingEventArgs e = {System.Windows.Forms.FormClosingEventArgs}) Line 432 Basic
System.Windows.Forms.dll!System.Windows.Forms.Form.OnFormClosing(System.Windows.Forms.FormClosingEventArgs e) + 0x77 bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.CheckCloseDialog(bool closingOnly = false) + 0x8c bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FContinueMessageLoop(int reason, int pvLoopData, System.Windows.Forms.NativeMethods.MSG[] msgPeeked) + 0x160 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = 4, int pvLoopData = 0) + 0x1ae bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = 4, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.Application.ModalApplicationContext}) + 0x177 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x61 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.RunDialog(System.Windows.Forms.Form form) + 0x33 bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window owner) + 0x370 bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog() + 0x7 bytes
App58.exe!App58.Form1.RB_pdf_Click(Object sender = {Text = "Exporter PDF"}, System.EventArgs e = {System.Windows.Forms.MouseEventArgs}) Line 1994 + 0xa bytes Basic发布于 2013-10-24 22:18:45
一个疯狂的猜测,你告诉我它是否正确。
按钮annulerBtn的属性annulerBtn设置为与None不同的属性。
或者将CancelButton或AcceptButton属性form3设置为annulerBtn。
如果其中一个条件为真,则无论是否调用Close方法,单击该按钮时,窗体都会自动关闭。如果要停止此事件链,则应在退出单击事件之前将form3.DialogResult属性设置为DialogResult.None。(或删除上面的属性设置的窗体和按钮之间的关联)
https://stackoverflow.com/questions/19576547
复制相似问题