Forcing a SaveFileDialog box to open on top of the form instead of underneath it

supreme_good

Member
Joined
Sep 19, 2006
Messages
12
Programming Experience
Beginner
Hello all! I have a situation where I am opening a SaveFileDialog box but it opens underneath my form instead of over it. This is causing my users some confusion. Does anyone know of a way to force that dialog box to be topmost at all times?

Thanks to all for the help in advance!
 
When you show the dialog pass it a reference to the form it'll need to remain on top of.

As in, if you're opening the dialog from a form and you want it to always be on top of that form simply pass it 'Me' when you call Show()
ex:
SaveFileDialog.Show(Me)
 
Almost there...

When you show the dialog pass it a reference to the form it'll need to remain on top of.

As in, if you're opening the dialog from a form and you want it to always be on top of that form simply pass it 'Me' when you call Show()
ex:
SaveFileDialog.Show(Me)

Thanks for the advice! I have one other issue now though. This section of code is in a class and is run from a seperate thread. This caused me to get the "cross-thread" call violation error. I figured no worries just check for invokerequired and invoke as needed, right? Well it wasn't so easy after all. I implemented the following code;

VB.NET:
Delegate Sub DoSaveFileDialogBoxDelegate(ByVal oParentForm As frmCSGPrevBalances)

    Sub DoSaveFileDialogBox(ByVal oParentForm As frmCSGPrevBalances)

        If oParentForm.InvokeRequired Then

            Dim a As New DoSaveFileDialogBoxDelegate(AddressOf DoSaveFileDialogBox)

            oParentForm.Invoke(a)

        Else
            Dim SaveFilePath As New SaveFileDialog

            SaveFilePath.CreatePrompt = False
            SaveFilePath.OverwritePrompt = True
            SaveFilePath.FileName = "CSG_Deliquent_Balances"

            SaveFilePath.Filter = "Excel (*.xls) |*.xls;*.csv|(*.xlsx) |*.xlsx|(*.*) |*.*"

            If SaveFilePath.ShowDialog(oParentForm) = DialogResult.OK Then
                strPath = SaveFilePath.FileName
            Else
                RaiseEvent CloseWindow()
            End If
        End If

    End Sub

The code hits the if statement and correctly invokes the delegate sub but then nothing happens. The program just hangs indefinitely. Any clues about what I might be doing wrong? Of course it all works fine if I remove the form reference from the showdialog clause, but then i am back to square one.
 
I'm not sure to be honest, I don't do delegation very often so I'll need to get back to you on this (unless someone else gets to it first)
 
oParentForm.Invoke(a) has the same effect as calling DoSaveFileDialogBox() in the form thread, can you see what is missing? Btw don't you get a "Parameter count mismatch." error also?
 
oParentForm.Invoke(a) has the same effect as calling DoSaveFileDialogBox() in the form thread, can you see what is missing? Btw don't you get a "Parameter count mismatch." error also?

Thanks for checking in John. Unfortunately, that missing parameter is not actually missing...I simply managed to omit it in my original post. Here is a better copy of the code in question.

VB.NET:
    Delegate Sub DoSaveFileDialogBoxDelegate(ByVal oParentForm As frmCSGPrevBalances)

    Sub DoSaveFileDialogBox(ByVal oParentForm As frmCSGPrevBalances)

        If oParentForm.InvokeRequired Then

            Dim a As New DoSaveFileDialogBoxDelegate(AddressOf DoSaveFileDialogBox)

            oParentForm.Invoke(a, oParentForm)

        Else
            Dim SaveFilePath As New SaveFileDialog

            SaveFilePath.CreatePrompt = False
            SaveFilePath.OverwritePrompt = True
            SaveFilePath.FileName = "CSG_Deliquent_Balances"

            SaveFilePath.Filter = "Excel (*.xls) |*.xls;*.csv|(*.xlsx) |*.xlsx|(*.*) |*.*"

            If SaveFilePath.ShowDialog() = DialogResult.OK Then
                strPath = SaveFilePath.FileName
            Else
                RaiseEvent CloseWindow()
            End If
        End If

    End Sub

This code does not produce any errors that I am aware of...it simply just hangs when it hits the invoke command.
 
I can't see any problems with that code, if execution on secondary thread really is waiting to enter Invoke call that must mean that the 'receiving' UI thread is busy and not able to invoke that method.
 
Back
Top