Is there any way to print TRichedit without warptext?

Who is Participating?
Slick812Connect With a Mentor Commented:
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


what's warptext?
pmarkovAuthor Commented:
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.
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

what about to set worwrpa to false before printing?

(just a guess)
pmarkovAuthor Commented:
It doesn't help.
pmarkovAuthor Commented:
It doesn't help.
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.

pmarkovAuthor Commented:
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.

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
pmarkovAuthor Commented:
I had sent this message before printing RichEdit.Print('');
but it didn't help...
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.
pmarkovAuthor Commented:
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.
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.