OnMouseDownet
OnMouseUpdu
StringGrid. Voici ce que j'ai écrit vite fait, en utilisant l'unité
Mathpour la fonction
Maxpas indispensable. Il reste à bien initialiser les membres
FStartXet
FStartYlors de la création de ta
Form. Attention par contre, à veiller que toutes les cellules du
StringGridaient bien la même hauteur et la même largeur.
TForm1 = class(TForm) Sgr: TStringGrid; procedure SgrMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure SgrMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private FStartX: Integer; FStartY: Integer; public end; procedure TForm1.SgrMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin FStartX := X; FStartY := Y; end; procedure TForm1.SgrMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin Sgr.LeftCol := Max(Sgr.LeftCol + ((X - FStartX) div Sgr.DefaultColWidth), 0); Sgr.TopRow := Max(Sgr.TopRow + ((Y - FStartY) div Sgr.DefaultRowHeight), 0); end;
type
TPublicStringGrid = class(TCustomGrid);
procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,@+
Y: Integer);
var
FLeftCol : Integer;
FTopRow : Integer;
begin
if GetKeyState(VK_LBUTTON) < 0 then
begin
FLeftCol := TPublicStringGrid(StringGrid1).MouseCoord(X,Y).X;
FTopRow := TPublicStringGrid(StringGrid1).MouseCoord(X,Y).Y;
if (FLeftCol <> -1) and (FTopRow <> -1) then
StringGrid1.Cells[FLeftCol,FTopRow] := Format('C%d R%d',[FLeftCol,FTopRow]);
end;
end;
21 mars 2014 à 21:19
Merci beaucoup.
Je suis en effet parti sur ce genre de process mais en utilisant l'event OnMouseMouve pour avoir un déplacement continue.
Me reste à finaliser ça.
Bonne soirée.
Tec.