Solved

Rap

Posted on 2001-06-29
6
149 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
[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
  • 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
Independent Software Vendors: 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!

 
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

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

707 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