Voici le code qui me prend la tête depuis un non moment.
J'ai associé un composant TUpDown à un TImage pour afficher les icones d'un TImageList et pouvoir sélectionner l'icone désirée en naviguant dans le ImageList avec les flêches.
Le principe de base fonctionne (les icones s'affichent bien) mais les bornes minimum et maximum ne sont pas respectés, cela bloque avant la fin de la liste d'icones, et selon l'icone cliquée, pas au même endroit ! bref, la navigation dans le Timagelist est très aléatoire et dépend de la première l'icone sélectionnée... Je n'y comprend plus rien.

Voici 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
 
procedure TForm2.FormShow(Sender: TObject);
  UpDown1.Min := 0;
  UpDown1.Max := Form1.ImageList2.Count - 1;
  UpDown1.Increment := 1;
 
  Index := Infos^.FIcon;
    //UpDown1.Position := Index;   //Valeur en cours (???)
  DisplayIcon(Index);          //Call
end;
 
procedure TForm2.UpDown1ChangingEx(Sender: TObject; var AllowChange: Boolean;
  NewValue: SmallInt; Direction: TUpDownDirection);
begin
  if Direction=updUp then inc(Index,UpDown1.increment);
  if Direction=updDown then dec(Index,UpDown1.increment);
  if Direction=updNone then exit; 
  DisplayIcon(Index)                       
end;
 
Procedure TForm2.DisplayIcon(Index:Integer);
var Infos  : Pinfos;
begin
 {Vider l'image}
  Image1.Picture.Bitmap := nil;
 {Associer l'icone de la liste d'images dans TImage1 }
  Form1.ImageList2.GetBitmap(Index, Image1.Picture.Bitmap);
end;
D'avance merci,

Denis