Solved

Rap

Posted on 2001-06-29
6
144 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:duke_n
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, but How do I get those TSTrings???
DrawTextEx doesn't parse the string to TStrings for wordwrap
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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 video discusses moving either the default database or any database to a new volume.

762 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

12 Experts available now in Live!

Get 1:1 Help Now