Is there a way to wrap the text in a TPanel.Caption
in Delphi (in my case Delphi 6)?
make a Delphi TPanel caption wrap
5.8k Views Asked by wonderer At
2
There are 2 best solutions below
0

Here is code that actually works:
const
Alignments: array[TAlignment] of Longint = (DT_LEFT, DT_RIGHT, DT_CENTER);
VerticalAlignments: array[TVerticalAlignment] of Longint = (DT_TOP, DT_BOTTOM, DT_VCENTER);
var
Rect: TRect;
...
if ShowCaption AND (Caption <> '') then
begin
Rect := GetClientRect;
Canvas.Brush.Style := bsClear;
Canvas.Font := Self.Font;
Flags := DT_NOPREFIX OR
DT_WORDBREAK OR
VerticalAlignments[VerticalAlignment] OR
Alignments[Alignment];
Flags := DrawTextBiDiModeFlags(Flags);
DrawText(Canvas.Handle, PChar(Caption), Length(Caption), Rect, Flags);
end;
Not by default, I'm afraid. As you can see from the sourcecode for TPanel, the text is drawn by the DrawText( )-windows API:
You can either derive and override the Paint-method, or you could just use a label instead.