Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Print preview, a couple of monitors and High/Low DPI

Hi,

I have interesting problem and I don't know why. On my computer I have connected 2 monitors, the primary is 4K and the secondary is normal full HD. In our application the TppReports are on different datamodules except for maybe a couple of forms. There are quite some datamodules around the application.

If I run our application on my secondary monitor, most of the print previews show on that monitor while on some show on the primary monitor. The code to display the print preview is more or less similar:

with ppRepCenik do begin Template.FileName := sReport; Template.LoadFromFile; if not AEmail then begin //Printing... if glSkupno.Nastavitve.Predogled then DeviceType := cRBOutputScreen else DeviceType := cRBOutputPrinter; UseLegacyPrinterDialog := not glSkupno.Nastavitve.NoviPrintDialog; AllowPrintToFile := True; PrinterSetup.PrinterName := glSkupno.PrinterSetting.PrinterName; PrinterSetup.BinName := glSkupno.PrinterSetting.BinName; PrinterSetup.DocumentName := AReportNaziv; SavePrinterSetup := True; PreviewFormSettings.SaveWindowPlacement := True; LanguageID := cRBLanguageSLO; ThumbnailSettings.Visible := False; Print; glSkupno.PrinterSetting.PrinterName := PrinterSetup.PrinterName; glSkupno.PrinterSetting.BinName := PrinterSetup.BinName; end else //Send e-mail begin sFolder := IncludeTrailingPathDelimiter(glSkupno.ProgramData.MapaTemp); sAttachment := Export2PDF(sMapa); if sAttachment <> '' then begin sSubject := ''; sBodyText := ''; SendEmail1('', sSubject, sBodyText, sAttachment); end; end; end;

We also use and override of TppPreview since we need to have an extra button on the toolbar. On this override form the settings for zoom and page display are loaded on BeforePreview and saved on ehToolbutton_Click (click on the close button - tag 11).

Since I can't figure out why the preview form is usually shown on the correct monitor and sometimes on wrong I was looking if it was possible to add the code to position the print preview at least on the monitor where is the main form or preferably on the form where the user pressed the print button. Any ideas?

We use Delphi 10.4 Sydney, RB 22.03 and use on Windows 10/11.

Thank You and best regards,
Goran
Goran Brumen
Audax d.o.o.

Comments

  • Sorry for the messed up code in ... I typed the message in Notepad++ and copied it here as the FireFox stopped responding twice while typing.
    Goran Brumen
    Audax d.o.o.
  • edited June 28
    Hi Goran,

    In your custom TmyPrintPreview class, try overriding the DoShow method to check the Monitor and move the location as needed.


    procedure TmyPrintPreview.DoShow;
    var
    lWorkAreaRect: TRect;
    liLeft: Integer;
    liTop: Integer;
    begin

    inherited;

    if Monitor <> Screen.ActiveForm.Monitor then
    begin

    liLeft := Left - Monitor.WorkareaRect.Left;
    liTop := Top - Monitor.WorkareaRect.Top;

    lWorkAreaRect := Screen.ActiveForm.Monitor.WorkareaRect;

    Left := liLeft + lWorkAreaRect.Left;
    Top := liTop + lWorkAreaRect.Top;

    end;

    end;




    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • Hi Nard,
    thank You very much, it helped. I must admit that I next day I wrote the question I found out where the problem lied. If the report has set property to open maximized (PreviewFormSettings.WindowState) then the report always opened on the primary monitor. I changed this setting to wsNormal and it works okay until user maximizes the preview form. Then SaveWindowPlacement opens the preview form maximized on secondary monitor unless the user changes preview form on primary fom, maximizes it and then moves back to secondary form and maximizes it again.

    I also tried Your code and works well with slight modifications:

    public
    procedure DoShow;

    procedure TppMyPrintPreview.DoShow;
    var
    iLeft, iTop: Integer;
    Mon : TMonitor;
    WorkAreaRct: TRect;
    begin
    inherited;

    Mon := Screen.MonitorFromWindow(Viewer.Handle, mdNearest);
    if Mon <> Screen.ActiveForm.Monitor then
    begin
    iLeft := Viewer.Left - Mon.WorkareaRect.Left;
    iTop := Viewer.Top - Mon.WorkareaRect.Top;

    WorkAreaRct := Screen.ActiveForm.Monitor.WorkareaRect;

    Viewer.Left := iLeft + WorkAreaRct.Left;
    Viewer.Top := iTop + WorkAreaRct.Top;
    end;
    end;
    Thank You for Your help and best regards,
    Goran
    Goran Brumen
    Audax d.o.o.
  • Hi Goran,

    My code sets Form Left, Top, where as your code is sets Viewer.Left, Top.

    TppViewer is control on the form. (TppViewer descends from TCustomPanel)

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited July 2
    Hi Nard,
    the problem is that I could not compile Your code so I have to update it a bit, hopefully working properly. So far it works. Otherwise, my print preview is descendand of TppPreview:

    type
    TppMyPrintPreview = class(TppPreview)

    I hope that is okay? I can send You full code of the unit on mail, maybe we can resolve the problem by email?

    Thank You and best regards,
    Goran
    Goran Brumen
    Audax d.o.o.
  • Hi Goran,

    I should have been more clear. My code is for a preview dialog descendant class.

    uses
    ppPrvDlg;

    type

    TmyPrintPreview = class(TppPrintPreview)
    protected
    procedure DoShow; override;

    end;


    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • Hi,

    unfortunately I still have problems with the previews. In our main software through the history we prepared few hundreds of reports and many of them are working as expected but some have problems with preview. Since our preview form is made according to the http://rbwiki.digital-metaphors.com/plugins/dialogs/preview-plugin/ due to the button or two we add, it is descendent from TppPreview class. I successfully implemented solution of positioning and sizing the preview form as per https://www.digital-metaphors.com/FORUMS/discussion/8723/save-preview-form-settings-per-user but this solution does not work for all of the reports. Let's say it works for 60-70%. I am spending hours searching the cause why some of these reports simply do not work. I tried to open and save them with the current version of RB hoping that would help but no success.

    So the reports that work are positioned as I wish on one of the two monitors, with a form of a size I choose. Those that simply refuse to work, are always positioned at left=0, top=0 and with width of let's say 831px and height 532 px. On some older reports I see that the buttons for page display are missing as well and when I move them form main (High DPI) monitor to secondary monitor (normal DPI), the labels, buttons, status bar etc. do not size down as they normally do. Any ideas?

    We are now using RB 22.05 build 229.

    Best regards,
    Goran
    Goran Brumen
    Audax d.o.o.
  • Hi,
    it looks like that the setting PreviewFormSettings.WindowState saved with report with wsMaximized makes problems. If I put in the code before calling Print this line
    PreviewFormSettings.WindowState := wsNormal;
    Reports show on expected position and size.

    Best regards,
    Goran
    Goran Brumen
    Audax d.o.o.
Sign In or Register to comment.