procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin with StringGrid1 do with Canvas do begin FillRect(Rect); DrawText(Handle, PChar(Cells[ACol, ARow]), Length(Cells[ACol, ARow]), rect, DT_WORDBREAK); end; end;
Rect: TRect; State: TGridDrawState);
begin
with StringGrid1 do
with Canvas do begin
FillRect(Rect);
DrawText(Handle, PChar(Cells[ACol, ARow]), Length(Cells[ACol, ARow]), rect, DT_WORDBREAK);
end;
end;
它是Windows的API函数,详细资料可以在msnd.microsoft.com上查到。
FillRect的作用每次输出文字时清除背景,不然每次DrawText时会导致文字重叠。