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
|
unit Unit1image;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ImgList, StdCtrls;
type
TForm1 = class(TForm)
BiblioImag: TListBox;
Container: TListBox;
procedure BiblioImagDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure FormCreate(Sender: TObject);
procedure ContainerDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure ContainerDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure ContainerDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Var MesBitmap: array[0..2] of tbitmap;
//==============================================================================
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
BiblioImag.Style:=lbOwnerDrawFixed;
Container.Style:=lbOwnerDrawFixed;
// taille des items en fonction de image
BiblioImag.ItemHeight:=60;
Container.ItemHeight:=60;
BiblioImag.Width:=80;
Container.Width:=80;
// chargement de ta bibliotheque de bitmap
for i:=0 to 2 do
begin
MesBitmap[i]:=Tbitmap.create;
MesBitmap[i].LoadFromFile('c:\phoenix1112\ICONES\'+inttostr(i)+'.Bmp');
BiblioImag.Items.Add(inttostr(i));
end;
end;
//==============================================================================
procedure TForm1.ContainerDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept :=false;
if (Source as TListBox).Name='BiblioImag' then Accept :=true;
end;
//==============================================================================
procedure TForm1.ContainerDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if (Source as TListBox).Name='BiblioImag' then
begin
Container.Items.Add((Source as TListBox).items[(Source as TListBox).itemIndex]);
end;
end;
//==============================================================================
procedure TForm1.ContainerDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with (Control as TListBox).canvas do
begin
textOut(Rect.left,Rect.Top,(Control as TListBox).Items[index]);
Draw(Rect.left,Rect.Top,MesBitmap[strtoint((Control as TListBox).items[index])]);
end;
end;
//==============================================================================
procedure TForm1.BiblioImagDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with (Control as TListBox).canvas do
begin
textOut(Rect.left,Rect.Top,(Control as TListBox).Items[index]);
Draw(Rect.left,Rect.Top,MesBitmap[index]);
end;
end;
//==============================================================================
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var i:integer;
begin
for i:=0 to 2 do MesBitmap[i].Free;
end;
end. |
Partager