2013-10-24 4 views
0

내 프로그램 (form1)에서 Form3.ShowDialog()으로 다른 양식 (form3)을 호출합니다. 이 양식은 진행률 막대로 추적되는 상대적으로 긴 프로세스를 실행합니다. 이 양식에는이 프로세스를 취소하는 버튼이 있으며 (pdf 문서 생성) 프로세스를 되돌릴 수 있습니다. 내가 프로세스를 종료하고 백업을 사용하여 변경 내용을 되돌리려이 버튼을 싶습니다MsgBox가 양식을 닫습니다

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 

다음과 같이 취소 버튼 (form3)에 대한

코드입니다.

현재 사용자 입력을 계속하려면 프로세스 내에서 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 
+0

원하는 것을 분명하지 않으면 문제를 표현하는 것이 어렵다고 생각하지 않습니다.이게 무엇입니까? '? 그리고'form'은 무엇을 참조합니까? ... 문제를 다시 말하십시오. –

+0

가장 중요한 코드를 주석 처리했습니다. 기본적인 디버깅 전략은 FormClosing 이벤트 핸들러를 추가하고 여기에 중단 점을 설정하는 것입니다. 호출 스택을보고 거기에 도달했는지 확인하십시오. –

+0

그래서 사용자가 '아니요'를 눌러도 'Me.Close()'를 호출하겠습니까? –

답변

3

야생 추측, 당신은 말해.

annulerBtn 버튼의 속성 DialogResultNone과 다른 것으로 설정됩니다. form3의
또는 재산 CancelButton 또는 AcceptButton이 조건 중 하나에 해당하는 경우 해당 버튼을 클릭하면, 다음 양식이이 Close 메소드를 호출 여부에 관계없이 자동으로 종료됩니다 annulerBtn

로 설정 . 이 이벤트 체인을 중지하려면 click 이벤트를 종료하기 전에 속성을 DialogResult.None으로 설정해야합니다. (또는 위의 속성에 따라 폼과 버튼 설정 사이의 연관성을 제거하십시오)

관련 문제