如何自绘stringgrid的网格线?要求能控制某行或某列的空格线。效果类似下面所示。
 ——————————————————————|
|      |            |                        |
|——————————————————————|                                            
|      |            |                        | 
|      ———————————————————|
|      |            |————————————| 
|      ———————————————————|                                           |      |            |                        |
|——————————————————————|
|      |            |                        |                               
|——————————————————————|                                          |
|      |            |                        | 
 ——————————————————————|

解决方案 »

  1.   

    你可以用下面这个达到你想要的效果
    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;
      

  2.   

    to:yinzhiw(不懂OOP)
     可否讲详细些, type
      TStringGridEx = class(TStringGrid); 这是定义的一个新的类,是什么作用?能否有详细的代码呢?谢谢!
      

  3.   

    你把那个去掉把,然后把TStringGridEx(Sender)
    改为 StringGrid1.canvas 就可以了
      

  4.   

    to:yinzhiw(不懂OOP)
    我试了你的代码,虽然不能达到我的要求:随意控制某行某列的网格线,但我还是非常感谢你的帮助!
      

  5.   

    To: huziandhuzi(胡子) 
    你说的随意控制某行某列的网格线是什么意思?
    在前面加一个判断条件不就可以了吗?
      

  6.   

    其实效果就象word表格合并某行或者某列后的效果,如下所示,谢谢!
    sssssssssssssssssssss
    s    s              s 
    sssssssssssssssssssss
    s    s       s      s 
    s    ssssssssssssssss
    s    s              s
    sssssssssssssssssssss
    s                   s  
    sssssssssssssssssssss
    ssssssssssssssssssssss
      

  7.   

    可能我表书的不是很清楚,如上图所示,4行0列,5行0列,这两个cell之间就没有网格线,
    感谢关注!
      

  8.   

    To: huziandhuzi(胡子) 
     你可以根据 ACol,ARow 来判断的啊,如果是4行0列,5行0列就不画线就是了
      

  9.   

    谢谢yinzhiw(不懂OOP)给我的思路,我想我会作出来的