Tuesday, February 12, 2008

PageSetupDlg Misreporting Margins Problem

I was having trouble in Delphi because the TPageSetupDialog component was repoting the margins at o.5 inches but when the dialog was shown the margins were all shown as 1 inch. If the cancel button is pressed the margins are still reported as 0.5 inches. If the OK button is pressed the margins are now reported at 1 inch and the control and the screen now match up.

This is obviously confusing for a user. The program reads 0.5 inch margins from the dialog and uses these values. The user looks at the dialog and sees 1 inch margins and thinks everything is OK. The the printout shows 0.5 inch margins and the user starts to attack the computer.

The problem is that the pagesetupdlg defaults to 1 inch margins instead of using the values in the rtMargin parameter of the PAGESETUPDLG Structure (which is the Rect object the Delphi maps to its TPageSetupDialog properties).

To solve this set the psoMargins flag and the dialog will use the values in rtMargin instead of its silly defaults.

No comments: