Thx für Ihre berät @DannyJames und @ChrisDunaway.
Irgendwie konnte ich herausfinden (mit beiden meiner Fragen und Ihre Antworten), dass die SaveFileDialog.ShowDialog(Me)
muss einen Verweis auf das Formular Me
.
Erst dann der Savefiledialog richtig ohne Fehler laden oder sogar bricht seine Forderung ohne weitere Benutzer-Aktion.
Leider habe ich den Download-Teil in eine vb-Klasse, die nicht von Inherits System.Windows.Forms.Form
geerbt wurde, so dass sie keinen Verweis auf ein Formular hat (was offensichtlich erforderlich sein muss).
Ich habe meinen Code geändert, so dass ich Verweise auf Formulare habe (so dass ich den Verweis auf ein Formular verwenden könnte, wie Me
in Formularklasse). Und es funktioniert wie ein Zauber.
Zur Vervollständigung hier ist ein solches Beispiel:
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
ich hoffe ich für andere Menschen das Problem richtig beschreiben könnte dieses Problem
@downvoter suchen: Sie sollten einen Kommentar, warum Sie meine Frage downvoted. Vielleicht sollte ich einige fehlende Informationen oder andere hinzufügen ... Im Moment denke ich, es ist gültig Frage –
Was haben Sie im Debugging-Modus versucht? –
Kann es im Puffer der Tastatur zu einem fehlerhaften Tastendruck kommen? Wie wird der Dialog ausgelöst? Ist es durch Eingabe über Tastatur oder Maus? Wie lauten die "CancelButton" - oder "AcceptButton" -Eigenschaften des Formulars? –