由于cxgrid只画出记录条数的表格线,当记录不满一表格时特别难看,所以我想通过自画把空白的部分补齐,但是补齐后当表格窗口前面打开另一个比表格小的窗口。当此窗口关闭后,会在cxgrid表格上留下一个原关闭窗口的空白影子,只有刷新表格后空白影子才消失。截图:
是在cxgrid的cxgrdtab1CustomDrawCell中调用
画表格代码:
- C# code
function DrawFullGrid(GridTableView: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo): Boolean;var i: Integer; lMaxRow: Integer; Rect1: TRect; ABorder: TcxBorder;begin ACanvas.FillRect(AViewInfo.Bounds); ACanvas.DrawText(AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index], AViewInfo.Bounds, cxAlignHCenter); //计算最多画多少行 lMaxRow := AViewInfo.GridViewInfo.NoDataInfoTextAreaBounds.Bottom - AViewInfo.GridViewInfo.NoDataInfoTextAreaBounds.Top mod AViewInfo.Bounds.Bottom - AViewInfo.Bounds.Top + 2; if AViewInfo.GridRecord.Index = GridTableView.ViewData.RecordCount - 1 then begin for i := GridTableView.ViewData.RecordCount + 1 to lMaxRow do begin //画表格 Rect1.Top := AViewInfo.Bounds.Top - 1 + (AViewInfo.Bounds.Bottom - AViewInfo.Bounds.Top) * (i - GridTableView.ViewData.RecordCount); Rect1.Bottom := AViewInfo.Bounds.Bottom + (AViewInfo.Bounds.Bottom - AViewInfo.Bounds.Top) * (i - GridTableView.ViewData.RecordCount); Rect1.Left := AViewInfo.Bounds.Left - 1; Rect1.Right := AViewInfo.Bounds.Right + 1; if AViewInfo.GridView.Styles.Content <> nil then ACanvas.Brush.Color := AViewInfo.GridView.Styles.Content.Color else ACanvas.Brush.Color := clWhite; if (i mod 2) = 0 then if AViewInfo.GridView.Styles.ContentOdd <> nil then ACanvas.Brush.Color := AViewInfo.GridView.Styles.ContentOdd.Color else if AViewInfo.GridView.Styles.ContentEven <> nil then ACanvas.Brush.Color := AViewInfo.GridView.Styles.ContentEven.Color; ACanvas.FillRect(Rect1); ACanvas.Brush.Color := AViewInfo.BorderColor[ABorder]; ACanvas.FrameRect(Rect1); AViewInfo.GridViewInfo.Painter.ExcludeFromBackground(Rect1); end; end; Result := True;end;
------解决方案--------------------------------------------------------
我把你的代码贴到DrawCell中运行,关闭第二个窗口不会出现你说的情况啊
[code=Delphi(Pascal]
procedure TF_RolePopedom.cxGridDBTableView1CustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
i: Integer;
lMaxRow: Integer;
Rect1: TRect;
ABorder: TcxBorder;
begin
ACanvas.FillRect(AViewInfo.Bounds);
ACanvas.DrawText(AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index], AViewInfo.Bounds, cxAlignHCenter);
//计算最多画多少行
lMaxRow := AViewInfo.GridViewInfo.NoDataInfoTextAreaBounds.Bottom - AViewInfo.GridViewInfo.NoDataInfoTextAreaBounds.Top mod AViewInfo.Bounds.Bottom - AViewInfo.Bounds.Top + 2;
if AViewInfo.GridRecord.Index = cxGridDBTableView1.ViewData.RecordCount - 1 then
begin
for i := cxGridDBTableView1.ViewData.RecordCount + 1 to lMaxRow do
begin
//画表格
Rect1.Top := AViewInfo.Bounds.Top - 1 + (AViewInfo.Bounds.Bottom - AViewInfo.Bounds.Top) * (i - cxGridDBTableView1.ViewData.RecordCount);
Rect1.Bottom := AViewInfo.Bounds.Bottom + (AViewInfo.Bounds.Bottom - AViewInfo.Bounds.Top) * (i - cxGridDBTableView1.ViewData.RecordCount);
Rect1.Left := AViewInfo.Bounds.Left - 1;
Rect1.Right := AViewInfo.Bounds.Right + 1;
if AViewInfo.GridView.Styles.Content <> nil then
ACanvas.Brush.Color := AViewInfo.GridView.Styles.Content.Color
else
ACanvas.Brush.Color := clWhite;
if (i mod 2) = 0 then
if AViewInfo.GridView.Styles.ContentOdd <> nil then
ACanvas.Brush.Color := AViewInfo.GridView.Styles.ContentOdd.Color