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 59 60
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, Grids;
type
TIntegerArray = array of Integer;
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Déclarations privées }
Procedure Mon(Sender: TObject; Shift: TShiftState; X, Y: Integer);
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
s:string;
pos:TGridRect;
procedure TForm1.Mon;
begin
StringGrid1.MouseToCell(x,y,pos.Right,pos.Bottom);
if (pos.Right>0) and (pos.Bottom>0) then StringGrid1.Selection:=pos;
end;
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if ssRight in shift then
begin
StringGrid1.MouseToCell(x,y,pos.Left,pos.Top);
if (pos.Left>0) and (pos.Top>0) then
begin
pos.Right:=pos.Left;
pos.Bottom:=pos.Top;
StringGrid1.Selection:=pos;
StringGrid1.OnMouseMove:=Mon;
end;
end;
end;
procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Assigned(StringGrid1.OnMouseMove) then
StringGrid1.OnMouseMove:=nil;
end;
end. |
Partager