在stringgrid中画一个checkbox(50分)

  • 主题发起人 主题发起人 autumn
  • 开始时间 开始时间
A

autumn

Unregistered / Unconfirmed
GUEST, unregistred user!
我的stringgrid中有一列是“是”和“否”,想用checkbox表现。
如何实现?
 
去深度历险找一个改进的StringGrid控件就可以了
 
以前的帖子有,找找吧
 
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow:
Integer;
Rect: TRect; State: TGridDrawState);
begin
If not ( gdFixed In State ) and (aCol = 1) Then Begin
With (Sender As TStringgrid).Canvas Do Begin
brush.color := $E0E0E0;
// checkboxes look better on a non-white background
Fillrect( rect );
If Odd(aRow) Then
Draw( (rect.right + rect.left - FCheck.width) div 2,
(rect.bottom + rect.top - FCheck.height) div 2,
FCheck )
Else
Draw( (rect.right + rect.left - FNoCheck.width) div 2,
(rect.bottom + rect.top - FNoCheck.height) div 2,
FNoCheck )
End;
End;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
bmp: TBitmap;
begin
FCheck:= TBitmap.Create;
FNoCheck:= TBitmap.Create;
bmp:= TBitmap.create;
try
bmp.handle := LoadBitmap( 0, PChar(OBM_CHECKBOXES ));
// bmp now has a 4x3 bitmap of divers state images
// used by checkboxes and radiobuttons
With FNoCheck Do Begin
// the first subimage is the unchecked box
width := bmp.width div 4;
height := bmp.height div 3;
canvas.copyrect( canvas.cliprect, bmp.canvas, canvas.cliprect );
End;
With FCheck Do Begin
// the second subimage is the checked box
width := bmp.width div 4;
height := bmp.height div 3;
canvas.copyrect(
canvas.cliprect,
bmp.canvas,
rect( width, 0, 2*width, height ));
End;
finally
bmp.free
end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
FNoCheck.Free;
FCheck.Free;
end;
 
这样的问题太多了。注意检索。
 
多人接受答案了。
 
后退
顶部