TPrintPreview

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

TPrintPreview

Postby drew » June 15th, 2011, 3:48 pm

I am a new user of TPrintPreview. It looks like an excellent component but I must be doing something wrong. When I run the code below, expecting it to produce centred text in a frame around the whole page, it produces a page with the frame and centred text in the top left of the page (approx 2/3 of the page size). Can anyone tell me please what I need to do to get the expected result?

Code: Select all
{------------------------------------------------------------------------}
procedure TMainform.FormShow(Sender : TObject);
begin
  with PrintPreview do
    begin
      Units := mmLoMetric; {Unit = 0.1 mm}
      BeginDoc;
      try
        DrawFrameAndText;
      finally
        EndDoc;
      end;
    end;
end;
{------------------------------------------------------------------------}
procedure TMainForm.DrawFrameAndText;

const TheText = 'Testing';

var XPos : integer;

begin
  with PrintPreview,Canvas do
    begin
      Canvas.Pen.Width := XFrom(mmLoMetric,5); {0.5 mm}

      {Draw rectangle to distinguish the page area}
      with PageBounds do Rectangle(Left,Top,Right,Bottom);

      Font.Size := 40;
      Font.Name := 'Comic Sans MS';
      XPos      := (PageSize.X - Canvas.TextWidth(TheText)) div 2;

      Canvas.TextOut(XPos,0,TheText);
    end;
end;
Attachments
Capture.JPG
Sample output
Capture.JPG (35.94 KiB) Viewed 1834 times
drew
Member
Member
 
Posts: 4
Joined: June 15th, 2011, 9:58 am

Re: TPrintPreview

Postby Kambiz » June 16th, 2011, 9:55 am

Are you using the last version of the component?
What is version of your Delphi?
Could you please post the DFM content of the form too?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: TPrintPreview

Postby drew » June 16th, 2011, 10:42 am

Hi Kambiz,

I am using v5.61 of TPrintPreview and Delphi 5 (build 5.62). The dfm file is shown below. Hope you this helps you.

Best regards,
Drew

Code: Select all
object Mainform: TMainform
  Left = 502
  Top = 135
  BorderStyle = bsDialog
  Caption = 'Generic program'
  ClientHeight = 475
  ClientWidth = 341
  Color = 13684736
  Font.Charset = ANSI_CHARSET
  Font.Color = clNavy
  Font.Height = -13
  Font.Name = 'Comic Sans MS'
  Font.Style = []
  OldCreateOrder = False
  Scaled = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 18
  object gbPrint: TGradBtn
    Tag = 24
    Left = 128
    Top = 440
    Width = 84
    Height = 24
    BeginColor = 13684736
    EndColor = clWhite
    GradientStyle = gsRectangle
    Caption = 'Print'
    OnClick = gbPrintClick
    Font.Charset = ANSI_CHARSET
    Font.Color = clNavy
    Font.Height = -13
    Font.Name = 'Comic Sans MS'
    Font.Style = []
    TabOrder = 0
    TabStop = True
  end
  object PrintPreview: TPrintPreview
    Left = 0
    Top = 0
    Width = 337
    Height = 425
    Align = alNone
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Arial'
    Font.Style = []
    TabOrder = 1
    Units = mmLoMetric
    ShowPrintableArea = True
  end
end
drew
Member
Member
 
Posts: 4
Joined: June 15th, 2011, 9:58 am

Re: TPrintPreview

Postby Kambiz » June 16th, 2011, 2:46 pm

I couldn't regenerate the issue.

Check out your code without using with for Canvas and PageBounds. Maybe Delphi compiler is doing something wrong.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: TPrintPreview

Postby drew » June 16th, 2011, 4:17 pm

Hi Kambiz,

Thanks for your speedy reply. Because you could not duplicate the problem I started changing my display options to see if that had any effect. I am using Windows 7 OS with a display setting of 1920 x 1080 and a dual monitor setup. The control panel display utility has 3 options viz Smaller (100%), Medium (125%) and Larger (150%). I was using Larger as my eyesight is not perfect. When I changed this setting to Medium the problem disappeared and the program gave the expected result. I am not clever enough at computing to know why this should be. With your greater knowledge is there any way to keep my original settings and have TPrintPreview work as expected?

Best regards,
Drew
drew
Member
Member
 
Posts: 4
Joined: June 15th, 2011, 9:58 am

Re: TPrintPreview

Postby Kambiz » June 17th, 2011, 10:09 am

Even by increasing the screen DPI by 200% I couldn't regenerate the problem.
I think updating the display driver will fix the problem on your computer.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: TPrintPreview

Postby drew » June 20th, 2011, 9:27 am

Hi Kambiz,

Thanks for your input. I have updated both the driver for my monitor and the driver for my graphics card and the problem I have is still there. I may have to give up unless anyone else can give me a point in the right direction.

Best regards,
Drew
drew
Member
Member
 
Posts: 4
Joined: June 15th, 2011, 9:58 am


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest

cron