Solved

Rap

Posted on 2001-06-29
6
146 Views
Last Modified: 2010-04-06
I need to paint a word-wrap-paint a long string on a given TRect in canvas.

earlier I did it using a hidden TMemo, but now I need to do it manually.
please help me with that.
(basically I am getting a string, a canvas and a rect, and I need to transform it to TStrings).
0
Comment
Question by:duke_n
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:edey
ID: 6239621
I can flesh this out later, but TCanvas has three function, textWidth, textHeight & textExtent (the later returns both of the former). With these you can construct substrings, checking for the width of the currtent string in the canvas's current font.

GL
Mike
0
 
LVL 1

Author Comment

by:duke_n
ID: 6240317
I know about those functions.
but also I need to wrap words - not letters.

I need each time to find space, and if a single word is bigger than the line then I DO have to wrap it in the middle of it, and this is a pain in the butt. I would probably write it the most ugly and inefficient way
0
 
LVL 9

Accepted Solution

by:
ITugay earned 50 total points
ID: 6240379
Hi duke_n,

DrawText API function.

here is a sample:

var
  S: String;
  R: TRect;
begin
  S := Memo1.Lines.Text;
  R := ClientRect;

  DrawText(Canvas.Handle, PChar(S), Length(S), R, DT_WORDBREAK);
end;

-----
Igor
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 1

Author Comment

by:duke_n
ID: 6240463
Yes, great(but to immitate a Memo better I use DT_WORDBREAK or DT_EDITCONTROL - looked up in the help :) ).

A pity though. When I had TStrings I could draw them manually with even vertical gaps - this one cannot even center it vertically(even without gaps between lines): DT_VCENTER works only for singleline.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6240509
You can draw text from TStrings, no any problems. There is DrawTextEx API function that allow you to calclulate rectangle where the text will be placed without drawing. Use this function first time to calculate rectangle and second time to draw text. Do this steps for every line in TStrings.

------
Igor.

PS: look at DT_CALCRECT value for dwDTFormat parameter.
 

0
 
LVL 1

Author Comment

by:duke_n
ID: 6240601
Yes, but How do I get those TSTrings???
DrawTextEx doesn't parse the string to TStrings for wordwrap
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TVirtualStringTree  search using TEdit 7 121
FMX enumerated colours 2 99
Printing problem 2 91
Mobile Keyboard covers the display of the TMemo 3 86
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

776 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