控件:实现虚线的StringGrid

这个最先是发在朋友的网站 www.lihuasoft.net  上的,大家可以看看:

原来StringGrid的演示效果:

   

修改后的StringGrid的演示效果:

   

{** 
* 单元:DotLineGrid 
* 作者:网事如风 
* 作用:实现虚线的StringGrid 
* 使用: 
**}
 
unit DotLineGrid; 

interface 

uses 
 SysUtils, Classes, Controls, Grids, Types, Graphics; 

type 
 tDotLineGrid 
=  class(TStringGrid) 
 private 
  
{ Private declarations }  
 protected 
  
{ Protected declarations }  
  procedure DrawCell(ACol, ARow: Longint; ARect: TRect; 
   AState: TGridDrawState); override; 
 public 
  
{ Public declarations }  
 published 
  
{ Published declarations }  
 end; 

procedure Register; 

implementation 

procedure Register; 
begin 
 RegisterComponents(
' Samples ' , [tDotLineGrid]); 
end; 

procedure tDotLineGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; 
 AState: TGridDrawState); 
Var 
  I, TmpWidth : Integer; 
begin 
  Canvas.Pen.Color :
=  clblack; 
  Canvas.Pen.Style :
=  psSolid; 
  inherited DrawCell(ACol, ARow, ARect, AState); 

  TmpWidth :
=   0
  
for  I : =   1  to RowCount  do  
  begin 
    
if  ( (I  >   0 ) and (not odd( I ) ) ) then 
    begin 
      
// Canvas.Pen.Color := clblack; 
      Canvas.Pen.Style : =  psDot; 
    end 
    
else  
    begin 
      
// Canvas.Pen.Color := clblack; 
      Canvas.Pen.Style : =  psSolid; 
    end; 

    Inc(TmpWidth, RowHeights[I 
-   1 ] + 1 ); 
    Canvas.MoveTo( 
0 ,   TmpWidth  -   1  ); 
    Canvas.LineTo( Width, TmpWidth 
-   1  ); 
  end; 

  TmpWidth :
=   0
  
for  I : =   1  to ColCount  do  
  begin 
    Inc(TmpWidth, ColWidths[I 
-   1 ] + 1 ); 
    Canvas.MoveTo( TmpWidth 
-   1 ,     0  ); 
    Canvas.LineTo( TmpWidth 
-   1 ,  Width ); 
  end; 
end; 

end.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值