Solved

Using DrawText

Posted on 2001-08-12
3
518 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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi Slick812 - thanks for your help - just what I needed.

John
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
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…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

14 Experts available now in Live!

Get 1:1 Help Now