Solved

Using DrawText

Posted on 2001-08-12
3
527 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 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 328
Machine not responding during CopyFile() 3 104
control image tags in a string ? 12 142
Tvertscrollbox like a whatsapp layout 5 36
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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