Mega Code Archive

 
Categories / Delphi / Examples
 

Drawtextapi

Community Home > Delphi How can I have a TBitBtn component that has a word wrapped caption? - by Borland Developer Support Staff Question and Answer Database FAQ1754D.txt How can I have a TBitBtn component that has a word wrapped caption? Category :VCL Platform :All Product :All 32 bit Question: How can I have a TBitBtn component that has a word wrapped caption? Answer: The following example demonstrates drawing word wrapped text directly on a TBitBtn's glyph. Example: procedure TForm1.FormCreate(Sender: TObject); var R : TRect; N : Integer; Buff : array[0..255] of Char; begin with BitBtn1 do begin Caption := 'A really really long caption'; Glyph.Canvas.Font := Self.Font; Glyph.Width := Width - 6; Glyph.Height := Height - 6; R := Bounds(0, 0, Glyph.Width, 0); StrPCopy(Buff, Caption); Caption := ''; DrawText(Glyph.Canvas.Handle, Buff, StrLen(Buff), R, DT_CENTER or DT_WORDBREAK or DT_CALCRECT); OffsetRect(R, (Glyph.Width - R.Right) div 2, (Glyph.Height - R.Bottom) div 2); DrawText(Glyph.Canvas.Handle, Buff, StrLen(Buff), R, DT_CENTER or DT_WORDBREAK); end; end; 7/16/98 4:31:28 PM