procedure TForm13.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var LGrid :TDBGrid; LText:string; LTextWidth:tsize; begin//=====================================id================================== if Column.FieldName.Equals('id') then begin LGrid :=TDBGrid(Sender); LGrid.Canvas.Brush.Style := bsSolid; LGrid.Canvas.FillRect(Rect); LGrid.Canvas.Font.Size := LGrid.Font.Size - 1; LGrid.Canvas.Font.Color := clWhite; LGrid.Canvas.Brush.Color := clYellow; //进度 背景颜色 LGrid.Canvas.RoundRect(Rect.Left, Rect.Top , Trunc(Rect.Left + Column.Field.AsFloat / 12 * Rect.Width) //分母 , Rect.Bottom, 2, 2); Rect.Inflate(-1, -1); LGrid.Canvas.Pen.Style := psClear; LGrid.Canvas.Font.Color := clRed; // 字体颜色 LGrid.Canvas.Brush.Style := bsClear; LText := FormatFloat('##0', Column.Field.AsFloat) + ' %'; LTextWidth := LGrid.Canvas.TextExtent(LText); LGrid.Canvas.TextOut(Rect.Left + ( (Rect.Width div 2) - (LTextWidth.cx div 2)), Rect.Top + ((Rect.Height div 2) - (LTextWidth.cy div 2)), LText); end; //================================================================= end;
标签:DBGrid,显示,LText,进度条,Column,LGrid,Canvas,Font,Rect From: https://www.cnblogs.com/tulater/p/18355027