如何自绘stringgrid的网格线?要求能控制某行或某列的空格线。效果类似下面所示。
——————————————————————|
| | | |
|——————————————————————|
| | | |
| ———————————————————|
| | |————————————|
| ———————————————————| | | | |
|——————————————————————|
| | | |
|——————————————————————| |
| | | |
——————————————————————|
——————————————————————|
| | | |
|——————————————————————|
| | | |
| ———————————————————|
| | |————————————|
| ———————————————————| | | | |
|——————————————————————|
| | | |
|——————————————————————| |
| | | |
——————————————————————|
function ZoomRect(mRect: TRect; mZoom: Integer): TRect;
begin
Result.Left := mRect.Left - mZoom;
Result.Right := mRect.Right + mZoom;
Result.Top := mRect.Top - mZoom;
Result.Bottom := mRect.Bottom + mZoom;
end; { ZoomRect }type
TStringGridEx = class(TStringGrid);procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
TStringGridEx(Sender).OnDrawCell := nil;
try
TStringGridEx(Sender).Canvas.Pen.Color := clBlack;
TStringGridEx(Sender).DrawCell(ACol, ARow, Rect, State);
TStringGridEx(Sender).Canvas.Rectangle(ZoomRect(Rect, 1));
finally
TStringGridEx(Sender).OnDrawCell := StringGrid1DrawCell;
end;
end;
可否讲详细些, type
TStringGridEx = class(TStringGrid); 这是定义的一个新的类,是什么作用?能否有详细的代码呢?谢谢!
改为 StringGrid1.canvas 就可以了
我试了你的代码,虽然不能达到我的要求:随意控制某行某列的网格线,但我还是非常感谢你的帮助!
你说的随意控制某行某列的网格线是什么意思?
在前面加一个判断条件不就可以了吗?
sssssssssssssssssssss
s s s
sssssssssssssssssssss
s s s s
s ssssssssssssssss
s s s
sssssssssssssssssssss
s s
sssssssssssssssssssss
ssssssssssssssssssssss
感谢关注!
你可以根据 ACol,ARow 来判断的啊,如果是4行0列,5行0列就不画线就是了