//参考如下代码
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
vText: PChar;
begin
with TStringGrid(Sender) do begin
vText := PChar(Cells[ACol, ARow]);
Canvas.FillRect(Rect);
DrawText(Canvas.Handle, vText, StrLen(vText), Rect,
DT_CENTER or DT_VCENTER or DT_SINGLELINE); //<<--
{ TODO : 修改对齐方式 }
if gdFocused in State then begin
Rect.Left := Rect.Left + 1;
Rect.Top := Rect.Top + 1;
Rect.Right := Rect.Right - 1;
Rect.Bottom := Rect.Bottom - 1;
Canvas.DrawFocusRect(Rect);
end;
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
vText: PChar;
begin
with TStringGrid(Sender) do begin
vText := PChar(Cells[ACol, ARow]);
Canvas.FillRect(Rect);
DrawText(Canvas.Handle, vText, StrLen(vText), Rect,
DT_CENTER or DT_VCENTER or DT_SINGLELINE); //<<--
{ TODO : 修改对齐方式 }
if gdFocused in State then begin
Rect.Left := Rect.Left + 1;
Rect.Top := Rect.Top + 1;
Rect.Right := Rect.Right - 1;
Rect.Bottom := Rect.Bottom - 1;
Canvas.DrawFocusRect(Rect);
end;
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货