procedure TCDMAOptParamView.SgSystemDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);var X, Y: Integer; s: string;begin with TStringGrid(Sender) do begin s := Cells[ACol, ARow]; if TryStrToInt(s, X) then begin // 右 if (Rect.Right - Rect.Left) + 2 > Canvas.TextWidth(s) + 2 then X := Rect.Left + ((Rect.Right - Rect.Left) - Canvas.TextWidth(s)) + 2 else X := Rect.Left + 2; Y := (Rect.Bottom + Rect.Top - Canvas.TextHeight(s)) div 2; Canvas.TextRect(Rect, X, Y, s); // 或者用 // DrawText(Canvas.Handle, PChar(s), Length(s), Rect, DT_CENTER or DT_SINGLELINE or DT_VCENTER); //文字居中 end else begin // 左 X := Rect.Left + 2; Y := (Rect.Bottom + Rect.Top - Canvas.TextHeight(s)) div 2; Canvas.TextRect(Rect, X, Y, s); end; end;end;