Solved

Memo Printing

Posted on 2000-04-30
7
307 Views
Last Modified: 2010-04-04
I have a memo control loaded with a file. I want to align the first line of the file to center of the page when printed. Please give me an idea on this.
0
Comment
Question by:drnadeem
7 Comments
 
LVL 3

Expert Comment

by:lopem
ID: 2764219
If you are using a non proportional font, I think the job is a very easy one.

You need something like this (remember to include the Printers unit in your uses declaration):

To print the first string of the memo component, just do this:

 TempStr := Memo1.Lines[0];
 Printer.BeginDoc;
   Printer.Canvas.TextOut(0,x,TempStr);
 Printer.EndDoc;

If you want to align that string to the center of the page, you have to do something like this:

  NumberOfSpaces := (TotalCharsInLine - length(TempStr)) div 2

Just add the number of spaces to the front of the string you want to center...

Hope this helps...

Take care,
Lopem (Manuel López)
0
 
LVL 1

Expert Comment

by:rowisoft
ID: 2765372
Hello!

Why do you not use the TRichEdit component??

Robert
0
 
LVL 1

Author Comment

by:drnadeem
ID: 2766119
What does TotalCharsInLine means, is it the length of line[0] ?

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 3

Expert Comment

by:lopem
ID: 2766145
Dear drnadeem,

TotalCharsInLine is the total chars in the page, not in the string you want to center and print... i.e. if you have 80 chars on line and the string you want to center is 40 chars length, the formula

NumberOfSpaces := (TotalCharsInLine - length(TempStr)) div 2
                                          80            -             40            div 2

would be equal to 20. That means you have to add to TempStr 20 blank chars to the beginning to center the string in the paper when you print it.

best regards,
Manuel López (lopem)
0
 
LVL 1

Author Comment

by:drnadeem
ID: 2766220
What does TotalCharsInLine means, is it the length of line[0] ?

0
 
LVL 1

Author Comment

by:drnadeem
ID: 2766243
thanks lopem ... any other suggestions guys ? How about using format command?
0
 
LVL 3

Accepted Solution

by:
raidos earned 30 total points
ID: 2769007
I would probably write it something like this.

Procedure PrintMemo;
Var
  FontH,Loop : Integer;
Begin
  Printer.BeginDoc;
  FontH := Printer.Canvas.TextHeight(Memo.Lines[0]);
  Printer.Canvas.TextOut((Printer.PageWidth div 2)-
                         (Printer.Canvas.TextWidth(Memo.Lines[0]) div 2),0
                         ,Memo.Lines[0]);
  For Loop := 1 to Memo.Lines.Count-1 do
    Printer.Canvas.TextOut(0,Loop*FontH,Memo.Lines[Loop]);
  Printer.EndDoc;
End;

Not tested at all, but i think it should work.

Good Luck

//raidos
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question