Grid:
TStringGrid = class(TCustomStringGrid)
TCustomStringGrid =class(TCustomDrawGrid)
TCustomDrawGrid=class(TCustomGrid)
TCustomGrid=class(TCustomControl)
从StringGrid开始追踪,DrawCell到底怎么画出来的:
procedure TCustomStringGrid.DrawCell(aCol, aRow: Integer; aRect:TRect;
aState: TGridDrawState);
begin
inherited DrawCell(aCol, aRow, aRect,aState);
【
procedureTCustomDrawGrid.DrawCell(aCol,aRow: Integer; aRect: TRect;
aState:TGridDrawState);
var
OldDefaultDrawing: boolean;
begin
if Assigned(OnDrawCell) and not(CsDesigning inComponentState) then begin
PrepareCanvas(aCol, aRow, aState);
ifDefaultDrawing then
Canvas.FillRect(aRect);
//从这里看以看出,不管DefaultDrawing是否为真,ONCraw事件都会执行
OnDrawCell(Self,aCol,aRow,aRect,aState)
end else begin
//如果在设计阶段或者没有设置DrawCell过程,则使用默认的方法。
OldDefaultDrawing:=FDefaultDrawing;
FDefaultDrawing:=True;
try
PrepareCanvas(aCol, aRow, aState);
finally
FDefaultDrawing:=OldDefaultDrawing;
end;
DefaultDrawCell(aCol,aRow,aRect,aState);
【
procedureTCustomDrawGrid.DefaultDrawCell(aCol, aRow: Integer; var aRect:TRect;
aState: TGridDrawState);
begin
if goColSpanning in Options thenCalcCellExtent(acol, arow, aRect);
Canvas.FillRect(aRect);
ifCellNeedsCheckboxBitmaps(aCol,aRow) then
DrawCellCheckboxBitmaps(aCol,aRow,aRect);
ifFTitleStyle<>tsNative then
DrawColumnText(aCol,aRow,aRect,aState);
if (goFixedRowNumberingin Options) and (FixedCols >= 1) and (aCol = 0)then
DrawCellAutonumbering(aCol, aRow, aRect, IntToStr(aRow));
end;
】
end;
DrawCellGrid(aCol,aRow,aRect,aState);
if FTitleStyle=tsNative then
DrawColumnText(aCol,aRow,aRect,aState);
end;
】
if DefaultDrawing then begin
ifColumns.Enabled and (gdFixed in aState) and
(aCol>=FixedCols) and (aRow=0) then
//inherited already did
else
if notCellNeedsCheckboxBitmaps(aCol, aRow) then
DrawCellText(aCol, aRow, aRect, aState, Cells[aCol,aRow]);
end;
end;
procedure TCustomGrid.DrawCell(aCol, aRow: Integer; aRect:TRect;
aState: TGridDrawState);
begin
//===============aliyagoo===============
PrepareCanvas(aCol, aRow, aState);
Canvas.FillRect(aRect);
DrawCellGrid(aCol,aRow,aRect,aState);
end;