C
cnhotel
Unregistered / Unconfirmed
GUEST, unregistred user!
D7+ExpressQuantumGrid 5中的cxGrid控件,在XP下控件自带的Demo无法编译~~
看了它的一个演示例子,tvOrders列的CustomDrawCell事件内容如下:
procedure TCustomDrawTableViewDemoMainForm.tvOrdersCustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
ARec: TRect;
ATextToDraw: String;
AIsVertical: Boolean;
val: String;
procedure SetTextToDraw;
begin
ATextToDraw := AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index];
end;
begin
SetTextToDraw;
ARec := AViewInfo.Bounds;
ACanvas.Canvas.Font.Assign(FFonts[Integer(vtDetail), Integer(cdaCell)]);
case FCustomDrawingStyle[Integer(vtDetail), Integer(cdaCell)] of
cdsBkImage:
begin
ACanvas.Brush.Bitmap := nil;
ACanvas.Brush.Assign(FGridBrushDetailCell);
ACanvas.Canvas.FillRect(ARec);
end;
cdsGradient:
begin
AIsVertical := (FColorScheme[Integer(vtDetail), Integer(cdaCell)] = csGrey) or (FColorScheme[Integer(vtDetail), Integer(cdaCell)] = csGold);
DrawGradient(ACanvas.Canvas, ARec, ColorScheme[Integer(FColorScheme[Integer(vtDetail), Integer(cdaCell)]), 1], ColorScheme[Integer(FColorScheme[Integer(vtDetail), Integer(cdaCell)]), 0], 40, AIsVertical)
end;
cdsDependsOnData:
begin
ACanvas.Canvas.Brush.Style := bsSolid;
ACanvas.Canvas.Brush.Color := clBlueLight;
val := VarAsType(AViewInfo.GridRecord.DisplayTexts[tvOrdersPaymentType.Index], varString);
if val = '信用卡' then
ACanvas.Canvas.Font.Color := clRed
else
if val = '牡丹卡' then
ACanvas.Canvas.Font.Color := clBlue
else
if val = '龙卡' then
ACanvas.Canvas.Font.Color := clGreen;
if val = '绿卡' then
ACanvas.Canvas.Font.Color := clFuchsia;
ACanvas.Canvas.FillRect(ARec);
end;
end;
SetBkMode(ACanvas.Canvas.Handle, TRANSPARENT);
ADone := not (FCustomDrawingStyle[Integer(vtDetail), Integer(cdaCell)] in [cdsDefaultDrawing, cdsDependsOnData]);
if ADone then
ACanvas.DrawText(ATextToDraw, AViewInfo.Bounds, 0);
end;
这个例子可以指定满足特定条件的单元格所在行的颜色,但是不能满足仅仅指定特定单元格的背景色,我是菜鸟,希望大家帮指点.DBGrid里面的很多属性这个控件里面都没有~~不知道该如何处理~!~
高手顺便帮介绍下Canvas的含义和用法啊~~
看了它的一个演示例子,tvOrders列的CustomDrawCell事件内容如下:
procedure TCustomDrawTableViewDemoMainForm.tvOrdersCustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
ARec: TRect;
ATextToDraw: String;
AIsVertical: Boolean;
val: String;
procedure SetTextToDraw;
begin
ATextToDraw := AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index];
end;
begin
SetTextToDraw;
ARec := AViewInfo.Bounds;
ACanvas.Canvas.Font.Assign(FFonts[Integer(vtDetail), Integer(cdaCell)]);
case FCustomDrawingStyle[Integer(vtDetail), Integer(cdaCell)] of
cdsBkImage:
begin
ACanvas.Brush.Bitmap := nil;
ACanvas.Brush.Assign(FGridBrushDetailCell);
ACanvas.Canvas.FillRect(ARec);
end;
cdsGradient:
begin
AIsVertical := (FColorScheme[Integer(vtDetail), Integer(cdaCell)] = csGrey) or (FColorScheme[Integer(vtDetail), Integer(cdaCell)] = csGold);
DrawGradient(ACanvas.Canvas, ARec, ColorScheme[Integer(FColorScheme[Integer(vtDetail), Integer(cdaCell)]), 1], ColorScheme[Integer(FColorScheme[Integer(vtDetail), Integer(cdaCell)]), 0], 40, AIsVertical)
end;
cdsDependsOnData:
begin
ACanvas.Canvas.Brush.Style := bsSolid;
ACanvas.Canvas.Brush.Color := clBlueLight;
val := VarAsType(AViewInfo.GridRecord.DisplayTexts[tvOrdersPaymentType.Index], varString);
if val = '信用卡' then
ACanvas.Canvas.Font.Color := clRed
else
if val = '牡丹卡' then
ACanvas.Canvas.Font.Color := clBlue
else
if val = '龙卡' then
ACanvas.Canvas.Font.Color := clGreen;
if val = '绿卡' then
ACanvas.Canvas.Font.Color := clFuchsia;
ACanvas.Canvas.FillRect(ARec);
end;
end;
SetBkMode(ACanvas.Canvas.Handle, TRANSPARENT);
ADone := not (FCustomDrawingStyle[Integer(vtDetail), Integer(cdaCell)] in [cdsDefaultDrawing, cdsDependsOnData]);
if ADone then
ACanvas.DrawText(ATextToDraw, AViewInfo.Bounds, 0);
end;
这个例子可以指定满足特定条件的单元格所在行的颜色,但是不能满足仅仅指定特定单元格的背景色,我是菜鸟,希望大家帮指点.DBGrid里面的很多属性这个控件里面都没有~~不知道该如何处理~!~
高手顺便帮介绍下Canvas的含义和用法啊~~