0

I have a simple PrintDialog (code below). My application is a tray application, meaning it has no windows in it and only contains a few simple right click options from the tray icon. Given a file path, the application will open a print dialog and let the user print the item.

I am seeing the following issue...the first time the print works, the dialog pops up to the top, taking precedence over all of my other open programs. After the first, the print dialog is always opened behind everything else that I have opened. For example, I have a web browser open on my screen, the print dialog will open behind that every time after the first print.

PrintDialog pd = new PrintDialog();
if (pd.ShowDialog() == DialogResult.OK)
{
    ProcessStartInfo info = new ProcessStartInfo(filename);
    info.Arguments = "\"" + pd.PrinterSettings.PrinterName + "\"";
    info.CreateNoWindow = true;
    info.WindowStyle = ProcessWindowStyle.Hidden;
    info.UseShellExecute = true;
    info.Verb = "PrintTo";
    try { Process.Start(info); }
    catch (Exception e) {
        //  An exception occured while attempting to print
        return false;
    }
    return true;
}
1

1 Answer 1

4

I was able to find an answer in this post: Cannot show print dialog on the top of asp.net web control

Leaving the answer here as it took me multiple days to find something that actually worked. Hopefully this can be helpful to someone else.

//initialize a new window form  
Form currentForm = new Form();
//show the form 
currentForm.Show();
//Activate the form 
currentForm.Activate();
//Set its TopMost to true, so it will bring the form to the top 
currentForm.TopMost = true;
//Set it to be Focus 
currentForm.Focus()
//set the form.visible = false 
currentForm.Visible = false;
//start to show the print dialog 
printDialog.ShowDialog(currentForm)
//close the new form 
currentForm.Close();
Sign up to request clarification or add additional context in comments.

1 Comment

It might be a year later, but this helped me! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.