Solved

Memo Printing

Posted on 2000-04-30
7
305 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now