Posted on 2001-09-03
Last Modified: 2010-04-06

Is there any way to print TRichedit without warptext?

Question by:pmarkov
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
  • 6
  • 2
  • 2
  • +3
LVL 27

Expert Comment

ID: 6450570


what's warptext?

Author Comment

ID: 6450588
I am so sorry...

WRAP text.

If a line is too long it is wraping to the next line.
I don't want wraping. I just want to cut lines.
LVL 27

Expert Comment

ID: 6450619
what about to set worwrpa to false before printing?

(just a guess)
Technology Partners: 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!


Author Comment

ID: 6450627
It doesn't help.

Author Comment

ID: 6450654
It doesn't help.

Expert Comment

ID: 6450706
Just created this, and i hope it help:

function Printwithoutwrap(Text: string):string;
st := tstringlist.Create;
st.Text := Text;
st.Text := StringReplace(st.Text, #13#10, ' ', [rfReplaceAll]);
st.Text := StringReplace(st.Text, '  ', ' ', [rfReplaceAll]);
st.Text := StringReplace(st.Text, '   ', ' ', [rfReplaceAll]);
result := st.Text;

RichEdit2.Text := Printwithoutwrap(RichEdit1.Text);
//Then maybe u would print it from RichEdit2?
//Or do what u want

It returns the string, but in one long line.
If u wan tit should not be to hard to change it to strings intead, that way it supports bigger text.


Author Comment

ID: 6450731
Sorry but it is NOT the ansewr which I expected.

RichEdit has got a WordWrap property. If it is false RichEdit will be DISPLAY the text without wrap. But it doesn't affected to PRINTING of RichEdit.

RichEdit.Print uses SendMessage(PRichEdit.Handle, EM_FORMATRANGE, 1, Longint(@Range)) to print it. And I want to cut lines when they are printing, not when they are displaing on the screen.

LVL 10

Expert Comment

ID: 6450920
Does this help (I didn't test this yet):

  SendMessage(RichEdit1.Handle, EM_FMTLINES, 0, 0);

If you send this message before printing?

Regards Jacco

Author Comment

ID: 6452214
I had sent this message before printing RichEdit.Print('');
but it didn't help...
LVL 34

Expert Comment

ID: 6459610
hello pmarkov, , some time ago I needed to print a richedit with special margins, different on the top than the bottom, but showing this in the Richedit. I think maybe the windows printing is what is wraping your text, not the rich edit. But to get the margins I wanted, I had to use something like Printer.Canvas.TextOut(margin1, Printer.Canvas.TextHeight( RichEdit.Lines[CurrentLine]) * CurrentLine, RichEdit.Lines[CurrentLine]); I had to set the Printer.Canvas.Font also. I don't have that code anymore, but you may look to the printer settings to change the wrapping or go through the trouble of Printer.Canvas.TextOut.

Author Comment

ID: 6469829
Thank you Slick812 for idea.

I had tried this and it work good, but I have had a problem.

Printer.Canvas.TextWidth() returns wrond result. When I print something to the printer then this returns right result. Why? What must I do before acess TextWidth for the first time?

Thanks again.
LVL 34

Accepted Solution

Slick812 earned 200 total points
ID: 6472359
pmarkov, the printer uses a totally different numbering for Canvas placement, it does not use the "Pixels" we are used to using in delphi. AND these numbers are Different depending on the type of printer you are using. I haven't worked with Printer.Canvas in a while, Here is some code that seems to do what you want. When I printed this, it CUT OFF the lines that were too long . . . .

procedure TForm1.ButtonPrintCanvasClick(Sender: TObject);
i, PrintXpix, PrintYpix, TextHeight: Integer;
PrintXpix := GetDeviceCaps(Printer.Handle,LOGPIXELSX);
PrintYpix := GetDeviceCaps(Printer.Handle,LOGPIXELSY);
RichEdit1.WordWrap := False;
TextHeight := Printer.Canvas.TextHeight('M');
  for i := 0 to RichEdit1.Lines.Count-1 do
  Printer.Canvas.TextOut(PrintXpix div 3, (PrintYpix div 3)+ (TextHeight*i), RichEdit1.Lines.Strings[i]);

 - - - - - - - - - - - - -  --
notice that I used the
to get a pixel to inch thing. . . . if you call textWidth after BeginDoc and
 then you should get the right textWidth in the device units of the printer (NOT PIXELS), you may want to get a reference book for delphi and the Tprinter, or do a search here for "Printer.Canvas" or other printer things

Expert Comment

ID: 6900916
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> You cannot delete a question with comments, special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process for further information, if needed.

Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer but does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item in the future to seek help.

To view your open questions, please click the following link(s) and keep them all current with updates.

To view your locked questions, please click the following link(s) and evaluate the proposed answer.

------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link

Moderators will finalize this question if still open in 7 days, by either moving this to the PAQ (Previously Asked Questions) at zero points, deleting it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
Thank you everyone.
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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