C1PreviewPane.Print and the Win11 UnifiedPrintDialog

Posted by: wknauf on 7 April 2025, 10:17 am EST

  • Posted 7 April 2025, 10:17 am EST - Updated 7 April 2025, 10:24 am EST

    Since the Win11 22H2 update, the call to “C1.Win.C1Preview.C1PreviewPane.Print” shows the new UnifiedPrintDialog that ignores the current PageSetup. E.g. the document in preview is landscape, but the dialog is set to portrait, and the printed document thus has the wrong page setting. Also, the dialog complains that no preview is available.

    I created a minimal sample:

    PrintDialogTest.zip

    It creates a “C1PrintPreviewControl”, which renders a minimal “C1PrintDocument”. The property PageSetup.LandScape is true.

    When clicking the print button in the preview control, the Win11 dialog is shown, see screenshot.

    I played a bit with the “PrintDialog” (button to the right):

    • “PrintDialog.UseEXDialog = false” shows a Win2000 form. Landscape in PageSetup works fine, but it is not the expected result to show a totally outdated dialog.
    • “PrintDialog.UseEXDialog = true” results in the current behavior, where the PageSetup is ignored.

    Then I found a workaround here to set a registry key:

    https://www.vbforums.com/showthread.php?901260-The-modern-print-dialog-issue-after-Windows-11-22H2-update

    https://github.com/dotnet/wpf/issues/8355

    I could modify this registry key before I handle the click to the print button, and restore it afterwards. But first I wanted to ask here whether you have better suggestions for this?

    When previewing a C1FlexReport, we use a “C1.Win.FlexViewer.C1FlexViewerPane”, which seems to fallback to the old dialog in case of Win11 - I found this code snippet while debugging:

    printDialog.UseEXDialog = !Win32.IsWin11();

    This is also not the best solution, but at least the page setup problem is not obvious to the users.

    Best regards

    Wolfgang

    PS: I noticed this shortly after the release of Win11 22H2, but first thought that it was a Windows bug, as not even Notepad.exe can handle this properly. Then I forgot about this problem, and now first users are updated to Win11 and report this to us ;-).

  • Posted 8 April 2025, 12:26 am EST

    Hello Wolfgang,

    The issue still remains unresolved on Microsoft’s end, as noted here: https://answers.microsoft.com/en-us/windows/forum/all/when-printing-in-notepad-the-print-dialog-displays/9e3d4de8-827b-485f-926f-96a7f489ddf6

    On our side, we’ve also implemented the older PrintDialog. Unfortunately, beyond what you’ve already tried, we don’t have any better suggestions at this point. Sorry for the inconvenience.

    Regards,

    Uttkarsh.

  • Posted 8 April 2025, 4:30 am EST

    Thanks for the feedback!

    I created this WinForms issue as I found similar tickets only for WPF but not for WinForms: https://github.com/dotnet/winforms/issues/13264

    And I added the registry key workaround from previously mentioned links to our call to “PreviewPane.Print”. It checks whether the key is present and whether the value is “1” or not, then sets it to “1” if necessary. And after printing, the previous state is restored (value is deleted if it was not found before, or value is reset):

    Nullable<int> oldValue = null;
    const string VALUE_PREFER_LEGACY = "PreferLegacyPrintDialog";
    const string PATH_UNIFIEDPRINTDIALOG = "Software\\Microsoft\\Print\\UnifiedPrintDialog";
    if (C1.Util.Win.Win32.IsWin11() == true)
    {
      RegistryKey keyPreferLegacyDialog = Registry.CurrentUser.CreateSubKey(PATH_UNIFIEDPRINTDIALOG, true);
      object objOldValue = keyPreferLegacyDialog.GetValue(VALUE_PREFER_LEGACY);
      if (objOldValue == null)
      {
        //No key is present: set it:
        oldValue = null;
        keyPreferLegacyDialog.SetValue(VALUE_PREFER_LEGACY, 1);
      }
      else
      {
        //Key is present:
        oldValue = (int)objOldValue;
        if (oldValue != 1)
        {
          //Set it only if the value is not "1":
          keyPreferLegacyDialog.SetValue(VALUE_PREFER_LEGACY, 1);
        }
      }
      keyPreferLegacyDialog.Close();
    }
    try
    {
        this.PreviewPane.Print();
    }
    finally
    {
      //Restore old value:
      if (C1.Util.Win.Win32.IsWin11() == true)
      {
        RegistryKey keyPreferLegacyDialog = Registry.CurrentUser.CreateSubKey(PATH_UNIFIEDPRINTDIALOG, true);
        if (oldValue != null)
        {
          //Old Value was not "1": reset it again:
          if (oldValue.Value != 1)
          {
            keyPreferLegacyDialog.SetValue(VALUE_PREFER_LEGACY, oldValue.Value);
          }
        }
        else
        {
          //Delete value:
          keyPreferLegacyDialog.DeleteValue(VALUE_PREFER_LEGACY);
        }
        keyPreferLegacyDialog.Close();
      }
    }

    I suggest that you do the same internally in “Print”. Do you think this is possible?

    The same could be done in “C1.Win.FlexViewer.Print” (instead of showing the old Win2000 print dialog by setting “UseEXDialog = false”).

    Best regards

    Wolfgang

  • Posted 9 April 2025, 3:07 am EST

    Hello Wolfgang,

    Thank you for your suggestion.

    We sincerely apologize for the inconvenience; however, in our opinion, implementing a workaround in C1 WinForms controls that involves modifying registry values on the user’s machine doesn’t seem practical or feasible.

    Regards,

    Uttkarsh.

  • Posted 9 April 2025, 4:43 am EST

    I understand your concerns.

    Further discussion depends on the reactions to my .NET ticket. If Microsoft changes something in .NET10, followup changes on your side might be reasonable. Let’s wait what they do :wink:

    Best regards

    Wolfgang

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels