自己画,在private定义两个TBitmap
private
FCheck, FNoCheck : TBitmap;
表单FormCreate时
FCheck := TBitmap.Create;
FNoCheck := TBitmap.Create;
With FNoCheckdo
begin
Width := 13;
Height := 13;
Canvas.Pen.Color := clBlack;
Canvas.MoveTo(0, 0);
Canvas.LineTo(12, 0);
Canvas.LineTo(12, 12);
Canvas.LineTo(0, 12);
Canvas.LineTo(0, 0);
Canvas.MoveTo(1, 1);
Canvas.LineTo(11, 1);
Canvas.LineTo(11, 11);
Canvas.LineTo(1, 11);
Canvas.LineTo(1, 1);
end;
With FCheckdo
begin
Width := 13;
Height := 13;
Canvas.CopyRect(Canvas.ClipRect, FNoCheck.Canvas, Rect(0, 0, Width, Height));
Canvas.Pen.Color := clBlack;
for i:=3 to 5do
begin
Canvas.MoveTo(i, i+2);
Canvas.LineTo(i, i+5);
end;
for i:=6 to 9do
begin
Canvas.MoveTo(i, 12-i);
Canvas.LineTo(i, 15-i);
end;
end;
procedure TForm_databakup.TableListGridDrawCell(Sender: TObject;
ACol,
ARow: Integer;
Rect: TRect;
State: TGridDrawState);
var
pGrid : ^TStringGrid;
Area : TRect;
calign : DWORD;
begin
pGrid := @Sender;
if not (gdFixed in State) then
if ARow<(pGrid^.RowCount-1) then
with TStringGrid(Sender).Canvas do
begin
if ACol=0 then
begin
//要显示例的索引
brush.Color:=clWindow;
FillRect(Rect);
if pGrid.Cells[ACol,ARow]='yes' then
Draw((rect.right + rect.left - FCheck.width) div 2, (rect.bottom + rect.top - FCheck.height)div 2,FCheck)
else
Draw((rect.right + rect.left - FCheck.width) div 2,(rect.bottom + rect.top-FCheck.height) div 2, FNoCheck );
end;
end;
pGrid^.Canvas.Font.Color := pGrid^.Font.Color;
if ARow>0 then
begin
if ARow=pGrid^.Row then
pGrid^.Canvas.Brush.Color := clMoneyGreen
else
pGrid^.Canvas.Brush.Color := pGrid^.Color;
//if ACol=4 then
pGrid^.Canvas.Font.Color := clMedGray;
//序号,用灰色
if ARow=(pGrid^.RowCount-1) then
pGrid^.Canvas.Brush.Color := RGB(220,220,220);
if pGrid.Rows[ARow][2]<>pGrid.Rows[ARow][3] then
pGrid^.Canvas.Brush.Color := RGB(242,242,242);
end;
if (ACol>0)or(ARow=0)or(ARow=(pGrid^.RowCount-1)) then
if hds[ACol].width >0 then
with pGrid^do
begin
Canvas.FillRect(Rect);
Area:= Rect;
InflateRect(Area, -1, -1);
Area.Right := Area.Right - 3;
Area.Left := Area.Left + 2;
Area.Top := Area.Top + 1;
calign:=hds[ACol].align;
if ARow=0 then
calign:= DT_CENTER;
DrawText(Canvas.Handle, PChar(Cells[ACol,ARow]), Length(Cells[ACol, ARow]), Area, calign);
end;
end;