关于在DBGrid中绘色的问题! 请教: 在DBGrid中对整个Column或整条记录都可以进行绘色,但不知如何对DBGrid中的某一格进行绘色? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 procedure ReBrushDBGrid(Rect:TRect;Grid:TDBGrid;Column:TColumn; State:TGridDrawState;cColor:TColor);var B:TRect; iLeft:integer;begin if Column<>要填色的列 then Exit; B:=Rect; Grid.Canvas.Brush.Color := cColor; case Column.Alignment of taLeftJustify: iLeft := B.Left + 2; taRightJustify: iLeft := B.Right - Grid.Canvas.TextWidth(Column.Field.DisplayText) - 3; else iLeft := B.Left + (B.Right - B.Left) shr 1 - (Grid.Canvas.TextWidth(Column.Field.DisplayText) shr 1); end; Grid.Canvas.TextRect(B, iLeft, B.Top + 2, Column.Field.DisplayText);end; 好象在DRAWCELL的过程,有点儿忘了,参照你整个记录的那个,但不得用那个过程点,用下面的一个,因为第二个DRAW可以定义从哪到哪,就是可以定义从第几格到第几格.没有在单位电脑前,我也说不上,家里的电脑没装DELPHI,SORRY!!! 楼上的不对吧,应在DBGRID的一个过程中实现,然后与数据关联,这样的话,才能根据数据进行配色.具体的我忘了,明天看看,有上网再来回复! if (Rect.Top = TStringGrid(DBGrid1).CellRect(TStringGrid(DBGrid1).col,TStringGrid(DBGrid1).row).top) and (not (gdFocused in State)) then Dbgrid1.Canvas.Brush.Color := clRed; DBGrid1.DefaultDrawDataCell(Rect, Column.Field, State); 在DRAWCELL中,实现 ylhlove(ylh) 的内容,但需要进行小的改动。我不再公司记得不是特别清楚了,但是改变Canvas.Brush.Color 后好像又发送了重画消息,容易进入死循环。另外对当前State的各类型进行判断。但是注意:应该先记录下历史的Brush.Color,在单元个绘完后,再恢复历史Brush.Color。 关于delphi的cxgrid的一些问题 求助:关于加载.net vcl component控件问题 一个关于菜单的最简单问题,在线等 比较弱的问题,请不吝赐教 那位高手能提供modelmaker6.2如何使用?最好能提供一個項目的實際例子,着急!!非常感謝 想升级自己的机子,兄弟们给给意见 idpop删除邮件问题 根据名称的字符串值去调用函数 一个DELPHI数据库很菜的问题. 请看看我这段文件存取的程序有什么问题,高分相送!!!! 有没有详细讲述 VCL 的书藉 关于DBGrid的行和其他问题,急!!!
State:TGridDrawState;cColor:TColor);
var
B:TRect;
iLeft:integer;
begin
if Column<>要填色的列 then Exit;
B:=Rect;
Grid.Canvas.Brush.Color := cColor;
case Column.Alignment of
taLeftJustify:
iLeft := B.Left + 2;
taRightJustify:
iLeft := B.Right - Grid.Canvas.TextWidth(Column.Field.DisplayText) - 3;
else
iLeft := B.Left + (B.Right - B.Left) shr 1
- (Grid.Canvas.TextWidth(Column.Field.DisplayText) shr 1);
end;
Grid.Canvas.TextRect(B, iLeft, B.Top + 2, Column.Field.DisplayText);
end;