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:
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
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.
Audax d.o.o.
Comments
... I typed the message in Notepad++ and copied it here as the FireFox stopped responding twice while typing.
Audax d.o.o.
In your custom TmyPrintPreview class, try overriding the DoShow method to check the Monitor and move the location as needed.
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
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: Thank You for Your help and best regards,
Goran
Audax d.o.o.
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
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
Audax d.o.o.
I should have been more clear. My code is for a preview dialog descendant class.
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com