Bonsoir tout le monde.

J'essai de faire déplacer des panels qui sont enfant d'un strinGgrid selon le scroll horizontale.
Voilà mon code :

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, ExtCtrls, ComCtrls, StdCtrls;
 
type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Panel1: TPanel;
    Panel2: TPanel;
    StringGrid1: TStringGrid;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1TopLeftChanged(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
  Panel : Tpanel;
  MemoRow : Integer;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.FormCreate(Sender: TObject);
Var
i: Integer;
begin
  StringGrid1.colCount := 63;
  StringGrid1.RowCount := 63;
  StringGrid1.DefaultColWidth := 20;
  StringGrid1.DefaultRowHeight := 20;
  For i:=1 to 62 do
  Begin
    StringGrid1.Cells[i,0] := IntToStr(i);
    StringGrid1.Cells[0,i] := IntToStr(i);
  end;
 
Panel := TPanel.Create(Self);
Panel.Parent := Self.StringGrid1;
Panel.Name := 'ici1';
Panel.Caption := 'ici1';
Panel.Height := 20;
Panel.Width := 30;
Panel.Left := StringGrid1.ColWidths[1]*2;
Panel.Top := StringGrid1.DefaultRowHeight;
 
Panel := TPanel.Create(Self);
Panel.Parent := Self.StringGrid1;
Panel.Name := 'ici2';
Panel.Caption := 'ici2';
Panel.Height := 20;
Panel.Width := 30;
Panel.Left := StringGrid1.ColWidths[1]*10;
Panel.Top := StringGrid1.DefaultRowHeight*2;
 
Panel := TPanel.Create(Self);
Panel.Parent := Self.StringGrid1;
Panel.Name := 'ici3';
Panel.Caption := 'ici3';
Panel.Height := 20;
Panel.Width := 30;
Panel.Left := StringGrid1.ColWidths[1]*5;
Panel.Top := StringGrid1.DefaultRowHeight*5;
 
 
MemoRow := StringGrid1.LeftCol;
 
end;
 
procedure TForm1.StringGrid1TopLeftChanged(Sender: TObject);
Var
OldRow : Integer;
begin
 
  oldRow := StringGrid1.TopRow;
  if oldRow > MemoRow then
    Panel.Top := Panel.Top - StringGrid1.DefaultRowHeight
  else
    Panel.Top := Panel.Top + StringGrid1.DefaultRowHeight;
 
 
  MemoRow := oldRow;
  StringGrid1.Refresh;
end;
 
end.
J'ai fais simple pour la création dynamique des panels. (En réalité je fais cela dans une boucle et je renseigne plus de paramètre).

Le but de l'opération est que si je descend ou monte à l'aide de l'ascenseur, il faut que les objets enfant du StringGrid suivent proportionnellement.
Donc à un moment ils disparaissent vers le haut ou vers le bas et réapparaissent etc...


J'ai 2 problèmes :
Le premier : Si vous utiliser les petits fleches noires du bas ou du haut Horizontale, seul le dernier Panel bouge et pas les 2 autres. Si j'essai de détecter les composants par components count, alors la le TOP des Panels est multiplié par 3.
Est-il possible de faire ce que je cherche ? Déplacer les 3 Panels en même temps sachant qu'ils ont un TOP différent ?

Le deuxième : Lorsque l'on clique sur les petits fleches noires du StrinGrid le déplacement est normale (hors Problemes 1) mais si on clique au milieu de la bar le déplacement le top des composants devient incohérent. Je n'arrive pas a trouver la bonne formule qui me garantirais le placement correcte des composants Enfants.

Peut-être je fais une enorme erreur, n'hésiter pas de me dire si c'est idiot de ma part de faire cela !!!

Merci de votre aide.