Solved

Memo Printing

Posted on 2000-04-30
7
309 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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