在我的程序(form1)中,我調用另一個表單(表單3)Form3.ShowDialog()
。此表單運行一個相對較長的進程,並由進度條跟蹤。在這種形式下有一個按鈕來取消這個過程(生成PDF文檔)並恢復過程。MsgBox關閉表單
爲取消按鈕(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
我想此按鈕,以結束過程,並使用備份還原變化。
我目前正在遠離多線程和即時通訊過程中使用Application.DoEvents()
繼續採取用戶輸入。
如果用戶按下yes按鈕,則該功能按預期工作。但是,如果用戶按下否,過程將按預期繼續進行,但表格將在此後關閉!
調試表明它在用戶按下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
不清楚你想要什麼,我不認爲這是很難表達的問題,這是什麼形式,因爲它應該是'?而「形式」是指什麼? ...請嘗試改述你的問題。 –
您註釋了最重要的代碼。基本的調試策略是添加FormClosing事件處理程序並在其上設置斷點。看看調用堆棧,看看它是如何到達那裏的。 –
所以你想要它調用'Me.Close()',即使用戶沒有按下? –