Solved

Using DrawText

Posted on 2001-08-12
3
520 Views
Last Modified: 2012-05-05
Hi

I need to print text in a canvas using DrawText API.  When I call DrawText I only see text up to the first CRLF.  I am reading the text from a file. Is there a way (with the flags perhaps) to print all the text in the file in one hit even if it has carriage returns in it?

John
0
Comment
Question by:jdthedj
  • 2
3 Comments
 
LVL 33

Expert Comment

by:Slick812
ID: 6378489
hello idthedj, I have used DrawText to dupicate the text display of a mutiline edit (TMemo) window with the flags of DT_CALCRECT or DT_EDITCONTROL or DT_WORDBREAK, , , ,
like this

var
RectC: Trect;
FileText: String;

PaintBox1.Canvas.Brush.Color := clWindow;
RectC := PaintBox1.ClientRect;
PaintBox1.Canvas.FillRect(RectC);
DrawEdge(PaintBox1.Canvas.Handle, RectC, EDGE_SUNKEN, BF_RECT);
RectC := Rect(RectC.Left+5,RectC.Top+5,RectC.Right-10,RectC.Bottom - 10);
DrawText(PaintBox1.Canvas.Handle, PChar(FileText), -1, RectC, DT_CALCRECT or DT_EDITCONTROL or DT_WORDBREAK);

 - - - - - - - - - - - - - -
with the DT_WORDBREAK it will wordwrap the text to the Rectangle and do line breaks for carriage returns, you can change the DT_EDITCONTROL and DT_WORDBREAK flags to see the difference those make
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 50 total points
ID: 6380546
sorry, I copy and pasted the wrong line of code, , , here's the button click code that should work - -

procedure TForm1.Button1Click(Sender: TObject);
var
Ch: Char;
File1: TextFile;
RectC: TRect;
FileText: String;
begin
AssignFile(File1, 'E:\Compile\test.txt');
Reset(File1);
FileText := '';
while not Eof(File1) do
  begin
    Read(File1, Ch);
    FileText := FileText+Ch;
  end;
CloseFile(File1);
PaintBox1.Canvas.Brush.Color := clWindow;
RectC := PaintBox1.ClientRect;
PaintBox1.Canvas.FillRect(RectC);
DrawEdge(PaintBox1.Canvas.Handle, RectC, EDGE_SUNKEN, BF_RECT);
RectC := Rect(RectC.Left+5,RectC.Top+5,RectC.Right-5,RectC.Bottom - 4);
DrawText(PaintBox1.Canvas.Handle, PChar(FileText), -1, RectC, DT_EDITCONTROL or DT_WORDBREAK);
end;

- - - - - - - - - - - -
the DT_CALCRECT is used to change the RectC.Bottom to hold ALL of the text in the string, but it does NOT draw any text
0
 
LVL 3

Author Comment

by:jdthedj
ID: 6381559
Hi Slick812 - thanks for your help - just what I needed.

John
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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
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, fr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

21 Experts available now in Live!

Get 1:1 Help Now