Solved

Using DrawText

Posted on 2001-08-12
3
532 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
[X]
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
  • 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 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

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

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 97
Multiple image collision 13 108
Connect to SQL 2008 r2 server over the Internet 4 80
SQL Server Express automatically execute SQL or SP 8 65
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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