If you draw the text on the panel using your canvas, you must set the canvas font.
Some components and / or some versions of Delphi can either intentionally or as a side effect of a previous drawing task install Canvas.Font
, but you should not rely on it.
Therefore, before starting to draw text, it is recommended Canvas.Font := Font;
.
The same applies to Canvas.Brush
and Canvas.Pen
.
type TMyPanel = class(TCustomPanel) protected procedure Paint; override; end; procedure TMyPanel.Paint; var r: TRect; begin r := ClientRect; Canvas.Brush.Color := Color; Canvas.FillRect(r); // fill the background Canvas.Font := Font; DrawText(Canvas.Handle, 'Sample Text', -1, r, DT_SINGLELINE or DT_CENTER or DT_VCENTER or DT_EXPANDTABS or DT_NOPREFIX); end;
source share