Bonjour,
J'ai un soucis au niveau de l'étirement d'un control issu d'un autre...
Je m'explique.
1) j'ai créé lors d'un clique sur un PANEL, 7 petites poignées
2) Le TMyShape est spécifique après de longue recherche j'ai opté pour un compo perso :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 procedure TFDossierTiers.ControlMouseDown(Sender: TObject;Button: TMouseButton;Shift: TShiftState;X, Y: Integer); Var //... Poignes: Integer; MyShape : TMyShape; begin for Poignes := 0 to 7 do begin MyShape := TMyShape.Create(self); MyListShape.Add(MyShape); With MyShape do begin Parent := sPanelParent; Tag := Poignes; // On mémorise chaque indice de poigné Case Poignes of //... 3: // Poigné situé à droite au milieu begin Cursor := crSizeWE; Left := TMysPanel(Sender).Left + TMysPanel(Sender).Width; Top := TMysPanel(Sender).Top + (TMysPanel(Sender).Height div 2) - 2; end; //... 7: // Poigné situé à gauche au milieu begin Cursor := crSizeWE; Left := TMysPanel(Sender).Left - 4; Top := TMysPanel(Sender).Top + (TMysPanel(Sender).Height div 2) - 2; end; end; FocusControl := TMysPanel(Sender); // Mémorise à qui sont rattaché ces poignés OnMouseDown := PoigneMouseDown; OnMouseMove := PoigneMouseMove; OnMouseUp := PoigneMouseUp; end; end;
3) donc une fois qu'on clique sur le composant, les poignéés apparaissent. Ensuite, j'utilise ces 3 procédures pour à la fois déplacer les poignées et à la fois agrandir le composant qui est dans FocusControl.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 Type TMyShape = Class(TShape) private FFocusControl: TWinControl; protected property FocusControl: TWinControl read FFocusControl write FFocusControl; public constructor Create(AOwner: TComponent); override; End; Constructor TMyShape.Create(AOwner: TComponent); begin inherited; Brush.Style := bsClear; Brush.Color := clBlack; Width := 4; Height := 4; end;
Mais malheureusement je n'ai pas l'action souhaité !!!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
61
62
63
64
65
66
67
68
69
70
71 procedure TFDossierTiers.PoigneMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Var R: TRect; sPanel: TsPanel; begin if not Assigned(Sender) then exit; if not (Sender is TMyShape) then exit; if not Assigned(TControl(Sender).Parent) then exit; if not (TControl(Sender).Parent is TsPanel) then exit; sPanel := TsPanel(TControl(Sender).Parent); // Limite de déplacement With sPanel do Begin R.TopLeft := ClientToScreen(BoundsRect.TopLeft); R.BottomRight := ClientToScreen(BoundsRect.BottomRight); ClipCursor(@R); // On ne doit pas sortir de cette zone pendant le déplacement ou l'étirement End; GetCursorPos(oldPos); end; procedure TFDossierTiers.PoigneMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); Var NewPos: TPoint; FocusPoint: TPoint; FocusRect: TRect; begin if not Assigned(Sender) then exit; if not (Sender is TMyShape) then exit; if not Assigned(TControl(Sender).Parent) then exit; GetCursorPos(NewPos); With TMyShape(Sender) do begin FocusPoint := TMysPanel(FocusControl).Parent.ScreenToClient(Mouse.CursorPos); FocusRect := TMysPanel(FocusControl).BoundsRect; Case TMyShape(Sender).Tag of //... 3: // étirement de gauche à droite (sur la poignée de droite) begin FocusRect.Right := FocusPoint.X; Left := Left - oldPos.X + newPos.X; // déplacement de la poignée end; //... 7:// étirement de gauche à droite (sur la poignée de gauche) begin FocusRect.Left := FocusPoint.X; Left := Left - oldPos.X + newPos.X;// déplacement de la poignée end; end; TMysPanel(FocusControl).SetBounds(FocusRect.Left,FocusRect.Top,FocusRect.Right - FocusRect.Left,FocusRect.Bottom - FocusRect.Top); // On place le focuscontrol oldPos := newPos; end; end; procedure TFDossierTiers.PoigneMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if not Assigned(Sender) then exit; if not (Sender is TMyShape) then exit; if not Assigned(TControl(Sender).Parent) then exit; ClipCursor(nil); // On libère le clip end;
Lorsque j'utilise la poignée de droite en tout premier ça va, mais après c'est le délire, mes poignées ce barrent , elles deviennent... vivantes !!! mdr quand j'approche la souris elle s'en vont.. trop ptr
Est-ce quelqu'un peux me dire où je fais pas bien mon calcul ?
Merci à vous.
Partager