通过网盘分享的文件:DrawGrid.rar链接: https://pan.baidu.com/s/1ihZ1wFkPEVxr4v02dgMFVA 提取码: 81e https://www.packtpub.com/en-us/product/delphi-cookbook-second-edition-9781785287428/chapter/delphi-basics-1/section/making-an-owner-draw-control-aware-of-the-vcl-styles-ch01lvl1sec13 t 登录后复制 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; 1.2.3.4.5.6.7.8.9.10.11. 登录后复制 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; 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16. 原创作者: u_15216366 转载于: https://blog.51cto.com/u_15216366/11897842