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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
| implementation
{$R *.DFM}
var Count : integer; // Nombre d'items existants
CaptBtn : Array[0..14] of Array[1..4] of string; // pour les Captions des boutons
CaptLab : Array[0..14] of Array[1..4] of string; // pour les Captions des labels
const HItem = 55; //<- Hauteur d'un Item (on en aura besoin encas de suppression d'un Item
procedure PrepaCaptions;
begin // Pour l'Item0 :
CaptLab[0,1]:='Item0_Texte1';
CaptLab[0,2]:='Item0_Texte2';
CaptLab[0,3]:='Item0_Texte3';
CaptLab[0,4]:='Item0_Texte4';
CaptBtn[0,1]:='Item0_Nom1';
CaptBtn[0,2]:='Item0_Nom2';
CaptBtn[0,3]:='Item0_Nom3';
CaptBtn[0,4]:='Item0_Nom4';
// Pour l'Item1 :
CaptLab[1,1]:='Item1_Texte1';
CaptLab[1,2]:='Item1_Texte2';
CaptLab[1,3]:='Item1_Texte3';
CaptLab[1,4]:='Item1_Texte4';
CaptBtn[1,1]:='Item1_Nom1';
CaptBtn[1,2]:='Item1_Nom2';
CaptBtn[1,3]:='Item1_Nom3';
CaptBtn[1,4]:='Item1_Nom4';
end;
procedure InitialiserListBoxPerso(NbItems : integer);
const BtnWidth = 70; BtnHeight = 18;
var PanelItem : TPanel; ImageFond : TImage;
lab1,lab2,lab3,lab4 : TLabel;
Btn1,Btn2,Btn3,Btn4 : TButton;
ImageDeDroite : TImage;
i : integer;
begin Count :=NbItems; //<- on récupère au passage la valeur de count
with Form1 do
begin for i:=0 to NbItems-1 do
begin PanelItem := TPanel.create(Form1);
with PanelItem do
begin parent:=ScrollBox1;
left:=0; width:=ScrollBox1.width-4; height:=HItem;
top:=i*HItem;
visible:=true;
tag:=-22; //<- Prendre une valeur qcq différente de tous les Tag des autres Panels présents sur Form1
// (sera utile pour les supressions d'Items)
caption:=CaptBtn[i,1];
end;
ImageFond := TImage.create(Form1);
with ImageFond do
begin parent:=PanelItem;
width:=PanelItem.width; height:=HItem;
Stretch:=True;
tag:=-22;
Picture.Bitmap:=image2.Picture.Bitmap; //<- Même image de fond pour tous les Items pour l'instant
end;
// les 2 labels de gauche :
Lab1:=TLabel.create(Form1);
with Lab1 do
begin parent:=PanelItem;
left:=5; Top:=10;
Autosize:=True;
tag:=-22;
caption:=CaptLab[i,1];
end;
Lab2:=TLabel.create(Form1);
with Lab2 do
begin parent:=PanelItem;
left:=5; Top:=32;
Autosize:=True;
tag:=-22;
caption:=CaptLab[i,2];
end;
// Les 4 boutons du milieu :
Btn1 :=TButton.create(Form1);
with Btn1 do
begin parent:=PanelItem;
left:=100; Top:=5;
width:=BtnWidth; Height:=BtnHeight;
caption:=CaptBtn[i,1];
tag:=-22;
//onClick:=procedure-A-clarifier
end;
Btn2 :=TButton.create(Form1);
with Btn2 do
begin parent:=PanelItem;
left:=100; Top:=30;
width:=BtnWidth; Height:=BtnHeight;
caption:=CaptBtn[i,2];
tag:=-22;
//onClick:=procedure-A-clarifier
end;
Btn3 :=TButton.create(Form1);
with Btn3 do
begin parent:=PanelItem;
left:=Btn2.left+Btn2.Width + 5;
Top:= Btn1.top;
width:=BtnWidth; Height:=BtnHeight;
caption:=CaptBtn[i,3];
tag:=-22;
//onClick:=procedure-A-clarifier
end;
Btn4 :=TButton.create(Form1);
with Btn4 do
begin parent:=PanelItem;
left:=Btn3.left;
Top:= Btn2.top;
width:=BtnWidth; Height:=BtnHeight;
caption:=CaptBtn[i,4];
tag:=-22;
//onClick:=procedure-A-clarifier
end;
// les 2 Labels de Droite :
Lab3:=TLabel.create(Form1);
with Lab3 do
begin parent:=PanelItem;
left:=Btn4.left+Btn4.Width + 5;
Top:=Lab1.Top;
Autosize:=True;
caption:=CaptLab[i,3];
tag:=-22;
end;
Lab4:=TLabel.create(Form1);
with Lab4 do
begin parent:=PanelItem;
left:=Lab3.left;
Top:=Lab2.Top;
Autosize:=True;
caption:=CaptLab[i,4];
tag:=-22;
end;
// l'Image de droite :
ImageDeDroite := TImage.create(Form1);
with ImageDeDroite do
begin parent:=PanelItem;
height:=HItem-9; width:=height; //<- ici Image de 46x46
Left:=330; Top:=5;
ImageList1.Draw(ImageDeDroite.Canvas,0,0, i, True);
tag:=-22;
end;
end;
end;
end;
// Utilisation :
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin // Au click sur ce Button :
PrepaCaptions; //<- on déclare les string des captions
InitialiserListBoxPerso(2); //<- création dynamique d'initialisation avec 2 Items
end;
end. |
Partager