How about

  DrawFlags := DT_NOPREFIX or DT_EDITCONTROL or DT_WORDBREAK;
  DrawTextEx(Canvas.Handle, PChar(PaintString), Length(PaintString), Rect,
DrawFlags, nil);

That will wrap the text to fit the rect.

 
Regards

Sean
---------------------------------------
Sean Cross
mailto:[EMAIL PROTECTED]

Pics Print - The photo printing solution for Windows. 
http://www.picsprint.com

Rental Property Manager: Rental management made easy
http://www.Intuitex.com
  

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Richard R
> Sent: 17 December 2005 4:51 p.m.
> To: 'Delphi-Talk Discussion List'
> Subject: tool tip example and caption help
> 
> Thanks to every one's input and code I found on the net, I've 
> been able to come up with this so far.
> 
> http://i23.photobucket.com/albums/b358/remnar/ttexample.jpg
> 
> The only thing I need to do now is find a way to limit the 
> width so it wraps. I came up with a algorithm to determine 
> the amount of lines it would wrap to, but it's not perfect 
> and maybe you can help me with it. I use the following code 
> for my TtsxToggle and TtsxCommand controls and it works well 
> except when the text is 1 line and small.
> 
> procedure TtsxToggle.DrawCaption;
> var
>   r: TRect;
>   cy, op, p, l, tw: integer;
>   str, str1, substr: string;
>   strs: array of string;
> begin
>   with Canvas do begin
>     Font:= Self.Font;
>     Brush.Color:= Self.Color;
>     Brush.Style:= bsClear;
>     r:= RECT(5, 5, Width - 5, Height - 5);
>     //calculate number of possible lines of text
>     l:= 1;
>     str1:= Caption;
>     str:= '';
>     substr:= #10#13;
>     p:= Pos(substr, str1);
>     op:= p;
>     if (p > 0) then begin
>       while (Pos(substr, str1) > 0) do begin
>         str:= copy(str1, 1, Pos(substr, str1) - 1);
>         str1:= copy(Caption, p + 1, Length(Caption));
>         p:= p + Pos(substr, str1);
>       end;
>       l:= p div op + 1;
>     end
>     else begin
>       substr:= ' ';
>       str:= '';
>       str1:= Caption;
>       p:= Pos(substr, str1);
>       if (p > 0) then try
>         op:= 0;
>         while (Pos(substr, str1) > 0) do begin
>           op:= op + 1;
>           SetLength(strs, op);
>           strs[op - 1]:= copy(str1, 1, Pos(substr, str1) - 1);
>           str1:= copy(Caption, p + 1, Length(Caption));
>           p:= p + Pos(substr, str1);
>         end;
>         op:= op + 1;
>         SetLength(strs, op);
>         strs[op - 1]:= str1;
>         tw:= 0;
>         for p:= 0 to op - 1 do begin
>           tw:= tw + TextWidth(strs[p]) + 2;
>           if (tw > (r.Right - r.Left - 1)) then begin
>             l:= l + 1;
>             tw:= TextWidth(strs[p]) + 2;
>           end;
>         end;
>         if (l > op) then
>           l:= l - 1;
>       finally
>         strs:= nil;
>       end;
>     end;
>     cy:= TextHeight(Caption) * l; // lines of text applied
>     r.Top:= Height div 2 - cy div 2;
>     if (not Enabled) then begin
>       Font.Color:= RGB(245, 241, 244);
>       r:= RECT(r.Left + 1, r.Top + 1, r.Right + 1, r.Bottom + 1);
>     end;
>     case Alignment of
>       taLeftJustify:
>         DrawText(Canvas.Handle, PChar(Caption), 
> Length(Caption), r, DT_LEFT or DT_VCENTER or DT_WORDBREAK);
>       taRightJustify:
>         DrawText(Canvas.Handle, PChar(Caption), 
> Length(Caption), r, DT_RIGHT or DT_VCENTER or DT_WORDBREAK);
>       taCenter:
>         DrawText(Canvas.Handle, PChar(Caption), 
> Length(Caption), r, DT_CENTER or DT_VCENTER or DT_WORDBREAK);
>     end;
>     if (not Enabled) then begin
>       Font.Color:= RGB(150, 107, 48);
>       r:= RECT(r.Left - 1, r.Top - 1, r.Right - 1, r.Bottom - 1);
>       case Alignment of
>         taLeftJustify:
>           DrawText(Canvas.Handle, PChar(Caption), 
> Length(Caption), r, DT_LEFT or DT_VCENTER or DT_WORDBREAK);
>         taRightJustify:
>           DrawText(Canvas.Handle, PChar(Caption), 
> Length(Caption), r, DT_RIGHT or DT_VCENTER or DT_WORDBREAK);
>         taCenter:
>           DrawText(Canvas.Handle, PChar(Caption), 
> Length(Caption), r, DT_CENTER or DT_VCENTER or DT_WORDBREAK);
>       end;
>     end;
>   end;
> end;
> __________________________________________________
> Delphi-Talk mailing list -> [email protected] 
> http://www.elists.org/mailman/listinfo/delphi-talk
> 
> 


__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to