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
Solved

Rap

Posted on 2001-06-29
6
147 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

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…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

791 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