Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using DrawText

Posted on 2001-08-12
3
Medium Priority
?
552 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 34

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 34

Accepted Solution

by:
Slick812 earned 200 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

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!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

926 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