如何实现当stringgrid的CELL获取焦点的时候,有选择巨型框效果。(32)

  • 主题发起人 主题发起人 maill01
  • 开始时间 开始时间
M

maill01

Unregistered / Unconfirmed
GUEST, unregistred user!
效果如图:http://www.tianlisoft.com/down/stringgrid.JPG请问大家是如何实现的。
 
这个不是直接使用StringGrid控件,应该是从StringGrid或者DrawGrid里面继承下来,让后将DrawCell函数重写。
 
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids;type TForm1 = class(TForm) StringGrid1: TStringGrid; procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); private { Private declarations } public { Public declarations } end;var Form1: TForm1; IndexACol, IndexARow: Integer;implementation{$R *.dfm}procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);begin IndexACol := ACol; IndexARow := ARow;end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);var i, x1, x2, y1, y2: Integer; lastc: Tcolor;begin // if (IndexACol= 0) and (IndexARow = 0) then exit; if (IndexACol = ACol) and (IndexARow = ARow) then begin x1 := 0; for i := 0 to ACol - 1 do begin x1 := x1 + 1; x1 := x1 + StringGrid1.ColWidths; end; x2 := x1 + StringGrid1.ColWidths[ACol]; y1 := 0; for i := 0 to ARow - 1 do begin y1 := y1 + 1; y1 := y1 + StringGrid1.RowHeights; end; y2 := y1 + StringGrid1.RowHeights[ARow]; lastc := StringGrid1.Canvas.Pen.Color; StringGrid1.Canvas.Pen.Color := clred; StringGrid1.Canvas.Pen.Width := 2; StringGrid1.Canvas.Rectangle(x1 +1 , y1 +1 , x2 + 1, y2 +1 ); StringGrid1.Canvas.Pen.Color := lastc; end;end;end.
 
在DrawCell里自己画不就行了?就是画个框而已嘛
 
fanronghua 答案应该比较接近了。
 
可以直接使用advsstringgrid
 
尽管使用第三方控件也许可以实现这个目的,但不利于提高自己的水平。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部