?
Solved

Memo Printing

Posted on 2000-04-30
7
Medium Priority
?
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 120 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

800 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