1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
CheckBox1: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure CheckBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CheckBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
TCheckBox(sender).Checked := Not TCheckBox(sender).Checked;
end;
procedure TForm1.FormCreate(Sender: TObject);
Var
xrect: TRect;
begin
// On taille le check sans le caption
CheckBox1.Caption := '';
CheckBox1.Width := 17;
CheckBox1.Height := 17;
// On recupère les coordonnées de la cellule 1,1 et on centre
xRect.Left := StringGrid1.CellRect(1,1).Left +
(StringGrid1.CellRect(1,1).Right - StringGrid1.CellRect(1,1).Left) Div 2
- (CheckBox1.Width div 2);
xRect.Top := StringGrid1.CellRect(1,1).Top;
xRect.Right := StringGrid1.CellRect(1,1).Right;
xRect.Bottom:= StringGrid1.CellRect(1,1).Bottom;
// On place le Checkbox
CheckBox1.Parent := StringGrid1;
CheckBox1.BoundsRect := xRect;
end;
end. |
Partager