当鼠标移动到cxgrid某单元格上时如何改变这个单元格的背景颜色、字体颜色?(50)

  • 主题发起人 主题发起人 xzzcq
  • 开始时间 开始时间
X

xzzcq

Unregistered / Unconfirmed
GUEST, unregistred user!
根据cxgrid单元格值静态的好设其背景颜色、字体颜色,但当鼠标移动到某个单元格上时如何动态改变当前单元格的背景颜色、字体颜色?即指哪个单元格哪个单元格就突显示,离开时恢复正常?
 
procedure TScheResultFrm.dbgrdResultDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);begin //行斑马线效果 if (DsScheResultData.RecNo mod 2) = 0 then dbgrdResult.Canvas.Brush.Color:= TColor($FDF1F1) else dbgrdResult.Canvas.Brush.Color:= clWhite; if DsScheResultData.FieldByName('FCapacity').AsFloat = 1 then dbgrdResult.Canvas.Font.Color:= clRed; //选中行突出 if ((State = [gdSelected]) or (State=[gdSelected,gdFocused])) then begin dbgrdResult.Canvas.Brush.color:= clBtnFace; dbgrdResult.Canvas.Font.color:= clBlack; dbgrdResult.Canvas.Font.Style := [fsBold,fsitalic]; RzStatusPane.Caption:= '当前选中单据为 '+DsScheResultData.FieldByName('FBillno').AsString; end; if EditFlag then begin //模拟选中背景色 with TMyDBGrid(Sender) do begin if DataLink.ActiveRecord = Row-1 then begin Canvas.Brush.Color:= clBtnFace; Canvas.Font.color:= clBlack; Canvas.Font.Style := [fsBold,fsitalic]; end else begin if (DsScheResultData.RecNo mod 2) = 0 then dbgrdResult.Canvas.Brush.Color:= TColor($FDF1F1) else dbgrdResult.Canvas.Brush.Color:= clWhite; end; end; end; dbgrdResult.DefaultDrawColumnCell(Rect, DataCol, Column, State);end;~~~~~~~~~~~~~~~~~~~~~~~~~~~~给你一个Tdbgrid的,自己在分析一下吧!
 
楼主的分给得太少,让你憋三天先,三天后再给你答案
 
可能楼主分也不多,想多问两个问题。
 
注册6年了
 
唉,虽接触DELPHI很长时间了,但一直没有深入学,偶尔用用,因此仍是初级水平,让大家见笑了,要分容易,问题解决开贴再送分!
 
...implementation{$R *.dfm}var FFlag:Integer; FViewInfo:TcxGridTableDataCellViewInfo;procedure TForm1.cxGrid1DBTableView1CustomDrawCell( Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);begin if (FFlag=0) and (FViewInfo=AViewInfo) then ACanvas.Brush.Color:=clRed;end;procedure TForm1.cxGrid1DBTableView1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);var HitTest:TcxCustomGridHitTest;begin HitTest:=cxGrid1DBTableView1.GetHitTest(X,Y); if HitTest=nil then exit; if HitTest is TcxGridRecordCellHitTest then begin FFlag:=0; if FViewInfo<>nil then FViewInfo.Invalidate(false); FViewInfo:=TcxGridTableDataCellViewInfo(TcxGridRecordHitTest(HitTest).ViewInfo); FViewInfo.Invalidate(false); end else begin FFlag:=1; if FViewInfo<>nil then FViewInfo.Invalidate(false); FViewInfo:=nil; end;end;
 
多谢wangdonghai大侠指点!多谢!!!
 
请wangdonghai大侠到:非技术问题 ID:3973232 再接50分
 
后退
顶部