2017-04-04 2 views
1

2013의 SaveFileDialog 직접 ShowDialog를 호출 한 후 자동으로 닫힙니다() 나는 비주얼 스튜디오와 윈도우 7을 사용하고

내 응용 프로그램이 GeckoFx와 웹 브라우저-구성 요소입니다. 다운로드 이벤트에서 SaveFileDialog를 열려면 다음과 같이 실행하십시오. 그러나 경우에 따라 callong ShowDialog()가 호출 된 직후에 대화 상자가 사라지고 else-statement로 점프하는 DialogResult.Cancel을 반환합니다. 오류가 발생하지 않습니다.

왜 이런 일이 발생하는지 제안 해주세요. 내가 @DannyJames을 조언하고 @ChrisDunaway 당신을 위해 :-(...

 'Save file dialog 
     Dim saveFileDialog1 As New SaveFileDialog() 

     saveFileDialog1.Filter = "CSV file (*.csv)|*.csv|All files (*.*)|*.*" 
     saveFileDialog1.FilterIndex = 2 
     saveFileDialog1.RestoreDirectory = True 
     saveFileDialog1.FileName = e.Filename 
     saveFileDialog1.AutoUpgradeEnabled = False 
     saveFileDialog1.CheckPathExists = False 
     saveFileDialog1.InitialDirectory = globalParameters.getDownloadDirectory() 'globalParameters._downloadDirectory 

     dialogResultValue = saveFileDialog1.ShowDialog() 

     If dialogResultValue = DialogResult.OK Then 
      'should go on here first, if user presses okay 
     Else 
      ' I am coming to this point, althoug nobody pressed any cancel button or any other input had happened yet 
     End If 
+0

@downvoter를 검색하는 다른 사람들을 위해 적절하게 문제를 설명 할 수 희망 : 완료

여기에 그러한 예입니다 당신이 내 질문을 downvoted 왜 언급해야한다. 어쩌면 내가 누락 된 정보 또는 기타를 추가해야합니다 ... 지금 당장은 유효한 질문이라고 생각합니다 –

+0

디버깅 모드에서 어떤 시도를 했습니까? –

+0

키보드 버퍼에 잘못된 키 입력이있을 수 있습니까? 대화 상자는 어떻게 트리거됩니까? 키보드 또는 마우스 입력입니까? 폼의'CancelButton' 또는'AcceptButton' 속성은 무엇입니까? –

답변

0

들으을 이것에 대해 단서도 없어.

어떻게 든

나는 (내 질문과 답변의 모두) 알아낼 수있는 SaveFileDialog.ShowDialog(Me)는 양식 Me에 대한 참조를 필요로한다.

를 만 다음의 SaveFileDialog 오류없이 제대로로드 또는 다른 사용자 액션없이 전화를 취소도됩니다.

불행하게도 내가로 다운로드 부분을 넣어 Inherits System.Windows.Forms.Form에 의해 상속되지 않은 vb 클래스가 있으므로 Form에 대한 참조가 없습니다 (분명히 필요함).

양식에 대한 참조가 있으므로 (예 : 양식 클래스의 Me과 같은 양식 참조를 사용할 수 있도록) 코드가 변경되었습니다. 그리고 그것은 매력처럼 작동합니다.

Imports System.IO 
Imports Gecko 
Imports System 
Imports System.Windows.Forms 
Imports System.Drawing.Printing 
Imports System.Management 
Imports System.Threading 
Imports System.Runtime.InteropServices 
Imports System.Timers 

Public Class frmMain 

' [...] 
' ATTENTION, MORE CODE IS NEEDED TO RUN GECKOFX WITH AN URL BUT NOT DISPLAYED HERE AT THIS POINT, 
' SINCE IT ISN'T NEEDED HERE TO SHOW THE ACTUAL PROBLEM 

''' <summary> 
''' Startup-Functionalities, such as Gecko Xpcom-Start etc. 
''' </summary> 
''' <remarks></remarks> 
Public Sub New() 
    ' call initiliazer 
    InitializeComponent() 
    AddHandler Gecko.LauncherDialog.Download, AddressOf Me.LauncherDialog_Download 
End Sub 

''' <summary> 
''' see also 
''' http://quabr.com/19906621/how-to-handle-downloads-on-gecko15-with-mozilla-xul15-in-visual-basic 
''' or 
''' http://stackoverflow.com/questions/19906621/how-to-handle-downloads-on-gecko15-with-mozilla-xul15-in-visual-basic 
''' </summary> 
''' <param name="sender"></param> 
''' <param name="e"></param> 
''' <remarks></remarks> 
Public Sub LauncherDialog_Download(ByVal sender As Object, ByVal e As Gecko.LauncherDialogEvent) 

    Try 
     Dim P As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & Path.DirectorySeparatorChar & "tmp" 'globalParameters._downloadDirectory ' 
     If Not System.IO.Directory.Exists(P) Then System.IO.Directory.CreateDirectory(P) 

     Dim objTarget As nsILocalFile = Xpcom.CreateInstance(Of nsILocalFile)("@mozilla.org/file/local;1") 

     Using tmp As New nsAString(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + vbTab & "temp.tmp") 
      objTarget.InitWithPath(tmp) 
     End Using 

     If globalParameters._doNotShowDownloadPrompt Then 
      'only if user does not want to load saveFileDialog; not interesting at this point 
     Else 
      'Save file dialog 
      Dim saveFileDialog1 As New SaveFileDialog() 
      saveFileDialog1.Filter = "CSV file (*.csv)|*.csv|All files (*.*)|*.*" 
      saveFileDialog1.FilterIndex = 2 
      saveFileDialog1.RestoreDirectory = False 
      saveFileDialog1.FileName = e.Filename 
      saveFileDialog1.AutoUpgradeEnabled = False 
      saveFileDialog1.CheckPathExists = False 
      saveFileDialog1.InitialDirectory = globalParameters.getDownloadDirectory() 'globalParameters._downloadDirectory 

      Dim dialogResultValue As DialogResult 
      Try 
       dialogResultValue = saveFileDialog1.ShowDialog(Me) 
      Catch ex As Exception 
       logging.logInformation("Probleme beim laden des Dialogs: " & ex.ToString()) 
      End Try 

      If dialogResultValue = DialogResult.OK Then 
       Try 
        Dim par As New Parameters 
        par.sender = sender 
        par.e = e 
        par.mime = e.Mime 
        par.url = e.Url 
        par.fileName = saveFileDialog1.FileName 
        par.dialogResultValue = dialogResultValue 
        par.myStream = saveFileDialog1.OpenFile() 
        modMain.ThreadJob(par) 
       Catch ex As Exception 
        logging.logInformation("Error during loading File" & e.ToString) 
       End Try 
      End If 
     End If 

    Catch ex As Exception 
     logging.logInformation("Error during loading File" & ex.ToString) 
    Finally 
     ' nothing to to here 
    End Try 
End Sub 


Private Sub frmMain_Disposed(sender As Object, e As EventArgs) Handles Me.Disposed 
    RemoveHandler Gecko.LauncherDialog.Download, AddressOf Me.LauncherDialog_Download 
End Sub 
End Class 

나는이 문제를

관련 문제