通过网盘分享的文件:DrawGrid.rar
链接: https://pan.baidu.com/s/1ihZ1wFkPEVxr4v02dgMFVA 提取码: 81et
procedure TForm8.FormCreate(Sender: TObject); begin DrawGrid1.FixedRows := 0; DrawGrid1.FixedCols := 0; //去掉固定列 DrawGrid1.RowCount := 3; //3行 DrawGrid1.ColCount := 6; //六列 DrawGrid1.DefaultRowHeight := 64; //行高 DrawGrid1.DefaultColWidth := 130 ; //列宽 end;
procedure TForm8.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var LRect: TRect; aString: string; begin Randomize; ImageList1.Draw(DrawGrid1.Canvas,Rect.Left,Rect.Top,Random(6),true); //先画标 aString:=inttostr(Arow)+'行,'+ inttostr(Acol)+' 列'; LRect := Rect; LRect.Left := LRect.Left + ImageList1.Width; LRect.Top:= LRect.Top+ LRect.Height div 2 -DrawGrid1.Canvas.TextHeight('值') div 2; //文本 垂直居中 DrawGrid1.Canvas.Font.Color := clRed; DrawGrid1.Canvas.TextRect(LRect, aString, [TTextFormats.tfCenter, TTextFormats.tfVerticalCenter]); //再画 文本 end;
标签:Canvas,aString,自画,Top,DrawGrid1,LRect,Rect,图标 From: https://www.cnblogs.com/tulater/p/18388377