关于DrawCell的问题!

bwm2012 2012-01-02 11:55:57
我想问下,DrawCell 事件是什么意思,好像是什么自绘制, 请问这个事件只有 stringgrid 有吗?像我想改变一个stringgrid 已知坐标 的单元格的 字符串 颜色 怎么实现? 还有里面的属性具体怎么用 的 谁有这方面的 资料 给我说下谢谢, 最好 基础点的!
...全文
177 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
我看见佛 2012-01-02
  • 打赏
  • 举报
回复

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
with Sender as TStringGrid do begin
if (ARow mod 2 =0) then begin //当行为偶数色为
Canvas.Brush.Color := clBtnFace;//画布颜色
Canvas.font.Color:=clblack;//字体色
end
else
begin
Canvas.Brush.Color := clgreen;
Canvas.font.Color := clWhite;
end;
Canvas.FillRect(Rect);
canvas.textout(rect.Left,rect.Top,cells[Acol,ARow]);
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0] := '姓名';
StringGrid1.Cells[1,0] := '学号';
StringGrid1.Cells[2,0] := '班级';
StringGrid1.Cells[3,0] := '课程';
StringGrid1.Cells[4,0] := '分数';
StringGrid1.Cells[0,1] := '张三';
StringGrid1.Cells[1,1] := '001';
StringGrid1.Cells[2,1] := '高三一班';
StringGrid1.Cells[3,1] := '语文';
StringGrid1.Cells[4,1] := '9';
StringGrid1.Cells[0,2] := '李四';
StringGrid1.Cells[1,2] := '002';
StringGrid1.Cells[2,2] := '高三二班';
StringGrid1.Cells[3,2] := '数学';
StringGrid1.Cells[4,2] := '99';
StringGrid1.Cells[0,3] := '王五';
StringGrid1.Cells[1,3] := '001';
StringGrid1.Cells[2,3] := '高三一班';
StringGrid1.Cells[3,3] := '数学';
StringGrid1.Cells[4,3] := '19';
end;

网上很多的呀
bwm2012 2012-01-02
  • 打赏
  • 举报
回复
看不明白,能说清楚点吗?
我看见佛 2012-01-02
  • 打赏
  • 举报
回复
DGGroid
ListBox
ComBoBox都有类似的自绘事件

但我对StringGrid也不熟悉--->
感觉应该是用ACol, ARow: Integer来判断坐标所在的单元格
通过Rect设置画布范围
Cnvs := (Control as Tstringgrid).Canvas;
Cnvs.Brush.Color := clSkyBlue;
Cnvs.Pen.Color := clNavy;

大致应该是用到这些代码吧

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧