谁能变动TStringGrid的某一行的颜色呢?有谁能做到?

jjwsoft 2001-03-17 10:49:00
TDBGrid可以,TDrawGrid也可以!

但最实用的TStringGrid有谁可以做到呢?
...全文
104 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zcheny 2001-03-18
  • 打赏
  • 举报
回复
响应StringGrid的OnDrawCell事件,通过这种办法不仅可以设置行的颜色,还可以设置某列的颜色,字体,字符串显示是否居中,3D效果等等。
例子代码如下:
procedure TForm.GridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
S: String;
SLeft, STop: integer;
begin
with Grid.Canvas do
begin
Font.Charset := GB2312_CHARSET;
Font.Height := -15;
Font.Name := '宋体';
S := CZPGrid.Cells[ACol, ARow];
if gdFixed in State then
begin
Brush.Color := Grid.FixedColor; //设置背景颜色
Font.Color := clWindowText; //设置字体颜色
FillRect(Rect); //画背景
Rect.Right := Rect.Right + 1;
Rect.Bottom := Rect.Bottom + 1;
DrawEdge(Handle, Rect, BDR_RAISEDINNER, BF_RECT); //画三维效果
if ACol = 0 then
SLeft := Rect.Right - TextWidth(S) - 6 //第一列字符显示靠左,其他列居中
else
SLeft := (Rect.Left + Rect.Right - TextWidth(S)) div 2;
STop := (Rect.Bottom + Rect.Top - TextHeight(S)) div 2;
TextOut(SLeft, STop, S);
Exit;
end;
if gdSelected in State then // 画选中的效果,看你喜欢啦
begin
Font.Color := clWhite;
Brush.Color := clWindowText;
end
else
begin
Brush.Color := CZPGrid.Color;
Font.Color := CZPGrid.Font.Color;
end;
FillRect(Rect);
TextOut(Rect.Left + 2, Rect.Top + 2, CZPGrid.Cells[ACol, ARow]);
end;
end;
veryhappy 2001-03-18
  • 打赏
  • 举报
回复
DBGird1.Canvas.Font.Color :=clRed;
laza 2001-03-18
  • 打赏
  • 举报
回复
为什么不先搜索一下。
icewind 2001-03-18
  • 打赏
  • 举报
回复
你自己ownerdraw一下,不就可以啦
jjwsoft 2001-03-17
  • 打赏
  • 举报
回复
有谁会啊!

5,385

社区成员

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

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