以下是我写的 TXhFlatPanel 的部分代码:
procedure TCustomXhFlatPanel.Paint;
const
Alignments: array[TAlignment] of Longint = (DT_LEFT, DT_RIGHT, DT_CENTER);
var
Rect: TRect;
FontHeight: Integer;
Flags: Longint;
begin
Rect := GetClientRect;
DrawFrame(Canvas, Rect, BorderColor, BorderWidth);
with Canvas do
begin
Brush.Color := Color;
Brush.Style := bsSolid;
FillRect(Rect);
if not Assigned(FPicture.Graphic) or (FPicture.Graphic.Empty) then
begin
//nothing
end else
begin
if Stretch then
StretchDraw(Rect, FPicture.Graphic) // 拉伸作图!!!!
else
begin
//Brush.Bitmap := FPicture.Bitmap;
//FillRect(Rect);
Draw(0, 0, FPicture.Graphic); // 原始大小作图。
end;
end;
Brush.Style := bsClear;
Font := Self.Font;
FontHeight := TextHeight('W');
with Rect do
begin
Top := ((Bottom + Top) - FontHeight) div 2;
Bottom := Top + FontHeight;
end;
Flags := DT_EXPANDTABS or DT_VCENTER or Alignments[FAlignment];
Flags := DrawTextBiDiModeFlags(Flags);
DrawText(Handle, PChar(Caption), -1, Rect, Flags);
end;
end;