How can we set the settings for printing in the new print preview of windows 11?

394 Views Asked by At

We are struggling with the new print preview with windows 11. Before the print we are changing some settings based on some configuration of our program. This settings are applied to the old print dialog of windows, but on the new one our settings are ignored. Additionally there is the problem, starting the program in visual studio, the old print dialog is called. Starting the .exe directly, then new print dialog is shown.

I wrote a small example. I just want to have the orientation in Landscape (German: Querformat):

        private void PrintBt_Click(object sender, RoutedEventArgs e)
        {
            // Create the print dialog object and set options
            PrintDialog pDialog = new PrintDialog();
            pDialog.PrintTicket.PageOrientation = System.Printing.PageOrientation.Landscape;
            pDialog.PageRangeSelection = PageRangeSelection.AllPages;
            pDialog.UserPageRangeEnabled = true;

            // Display the dialog. This returns true if the user presses the Print button.
            Nullable<Boolean> print = pDialog.ShowDialog();
            if (print == true)
            {
                //XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
                //FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
                //pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
            }
        }

Calling it from visual studio I get the following and our setting is applied:

Legacy Print Dialog

Starting the .exe the new print dialog is opened, but without our settings: New print preview Windows 11

Is there a way to let visual studio open the correct print dialog?

How can we sent the print settings to the new print dialog of windows 11?

Right now we are out of ideas on how to fix it, because the wrong dialog is opened. We tried with the .NET 6 and with .NET Framework 4.8 and in both cases it's not working.

0

There are 0 best solutions below