未设置前效果,没有居中
居中代码
procedure TForm1.Stringgrid1DrawCell(Sender: TObject;
ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
with Sender as TStringGrid do
begin
Canvas.FillRect(Rect);
DrawText(Canvas.Handle, Pchar(Cells[ACol, ARow]),
Length(Cells[ACol, ARow]), Rect,
DT_CENTER or DT_SINGLELINE or DT_VCENTER);
end;
end;
加了居中代码后效果:
原来的字,和居中的字都会显示出来,这就尴尬了,说明有重影,设置一下
stringgrid1.deaultdrawing := False;
设置后效果效果:
完美收工!