Solved

Memo Printing

Posted on 2000-04-30
7
306 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 191
Working this component WebCopy with proxy, help 3 76
oracle global variables 4 63
Firemonkey android show image from resource ? 1 33
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

18 Experts available now in Live!

Get 1:1 Help Now