procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
dec(rect.Left, stringgrid1.gridlinewidth);
dec(rect.Top, stringgrid1.gridlinewidth);
inc(rect.Right, stringgrid1.gridlinewidth);
inc(rect.Bottom, stringgrid1.gridlinewidth);
stringgrid1.canvas.brush.Color:=clRed; // 改成你想要的颜色
stringgrid1.canvas.FrameRect(Rect);
stringgrid1.canvas.brush.Color:=clDefault;
end;
适用于:gridlinewidth=1的情况。>1就很难看了。 ^_^
一种办法就是用个for循环来画, 比如:
for i:=1 to stringgrid1.gridlinewidth do
begin
dec(rect.Left, stringgrid1.gridlinewidth);
dec(rect.Top, stringgrid1.gridlinewidth);
inc(rect.Right, stringgrid1.gridlinewidth);
inc(rect.Bottom, stringgrid1.gridlinewidth);
stringgrid1.canvas.brush.Color:=clRed; // 改成你想要的颜色
stringgrid1.canvas.FrameRect(Rect);
stringgrid1.canvas.brush.Color:=clDefault;
end;
可能效率上会有些影响。