PrintDialog call the result the print dialog always displays/ hides behind the Windows Form

dd8

Member
Joined
Jun 26, 2019
Messages
12
Programming Experience
10+
ve inherited a code application.

When I either run the exe or debug the code the result is
The print dialog box is called.
However the Print dialog always displays behind/ (appears as hidden or doesnt display) the Window Form.
How can I get the Print dialog to be the main focus, current active window and display in the front of Windwos forms.

Happens on both Windows 7 & Windows 10

Standard code to call the print dialog...

VB.NET:
Dim objPrintDialog As New PrintDialog

If objPrintDialog.ShowDialog = DialogResult.OK Then
    Invoke(New DelAppEnable(AddressOf AppEnable), False)


any ideas?
Thanks in Advance
 
Last edited by a moderator:
The fact that you are calling Invoke suggests that you are executing that code on a secondary thread. If you are, that is your problem. DO NOT do anything related to the UI on a secondary thread. Displaying a dialogue is obviously related to the UI.

Note that you actually can create forms and display them on other threads but those forms and the controls they contain are then owned by that thread and cannot be access from the UI thread, so you open a can of worms. Note also that modal dialogues, which you create when you call ShowDialog, are modal with respect to the thread that owns them, which means that your PrintDialog will not behave modally with respect to the form that displays it.
 
The fact that you are calling Invoke suggests that you are executing that code on a secondary thread. If you are, that is your problem. DO NOT do anything related to the UI on a secondary thread. Displaying a dialogue is obviously related to the UI.

Note that you actually can create forms and display them on other threads but those forms and the controls they contain are then owned by that thread and cannot be access from the UI thread, so you open a can of worms. Note also that modal dialogues, which you create when you call ShowDialog, are modal with respect to the thread that owns them, which means that your PrintDialog will not behave modally with respect to the form that displays it.
Thanks jmcilhinney, do you have an example I can view
 
Rather than display the dialogue and then invoke a method that does something, you need to invoke a method that displays the dialogue and then does something. You already have an example of invoking a method on the UI thread right there, so you don't really need an example of that from me. That said, if you're not completely comfortable with that whole concept, you might like to check this out.
 
Back
Top