?
Solved

Rap

Posted on 2001-06-29
6
Medium Priority
?
153 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 200 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
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!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 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