VCL Delphi

Title: Image ListBox
Question: Listbox in delphi with image in items ?
Answer:
This component is same Tlistbox Component but with extra ability for add/insert image into listbox item's . this demo show your all ability for this component . also you can download this demo by link .
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ImgList, jpeg, ExtCtrls, IListBox, Buttons;
type
TForm1 = class(TForm)
ImageList1: TImageList;
Panel1: TPanel;
Panel2: TPanel;
IListBox1: TIListBox;
Label2: TLabel;
Edit1: TEdit;
Insert: TBitBtn;
BitBtn2: TBitBtn;
BitBtn1: TBitBtn;
BitBtn3: TBitBtn;
RadioGroup1: TRadioGroup;
BitBtn4: TBitBtn;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
Panel3: TPanel;
Image1: TImage;
RB0: TRadioButton;
RB1: TRadioButton;
Image2: TImage;
RB2: TRadioButton;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Image6: TImage;
Image7: TImage;
Image8: TImage;
Image9: TImage;
Label1: TLabel;
RB8: TRadioButton;
RB9: TRadioButton;
RB7: TRadioButton;
RB6: TRadioButton;
RB5: TRadioButton;
RB4: TRadioButton;
RB3: TRadioButton;
Label3: TLabel;
Label4: TLabel;
procedure IListBox1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
function GetImageItemIndex() : integer;
procedure Image1Click(Sender: TObject);
procedure Image2Click(Sender: TObject);
procedure Image3Click(Sender: TObject);
procedure Image4Click(Sender: TObject);
procedure Image5Click(Sender: TObject);
procedure Image6Click(Sender: TObject);
procedure Image7Click(Sender: TObject);
procedure Image8Click(Sender: TObject);
procedure Image9Click(Sender: TObject);
procedure Label1Click(Sender: TObject);
procedure InsertClick(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn6Click(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure IListBox1KeyPress(Sender: TObject; var Key: Char);
procedure BitBtn5Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
Procedure CurrentItem();
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
BitMap : TBitmap;
i : integer=0;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.IListBox1Click(Sender: TObject);
begin
CurrentItem();
end;
Procedure TForm1.CurrentItem();
var
i,j : integer;
begin
i:=IListBox1.ItemIndex;
if i-1 then
begin
j:=IListBox1.GetImagIndex(i);
case j of
0 :
RB0.Checked:=true;
1 :
RB1.Checked:=true;
2 :
RB2.Checked:=true;
3 :
RB3.Checked:=true;
4 :
RB4.Checked:=true;
5 :
RB5.Checked:=true;
6 :
RB6.Checked:=true;
7 :
RB7.Checked:=true;
8 :
RB8.Checked:=true;
-1:
RB9.Checked:=true;
end;
Edit1.Text:=IListBox1.Items.Strings[i];
end;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
IListBox1.ItemIndex:=0;
IListBox1.SetFocus;
CurrentItem();
end;
procedure TForm1.BitBtn4Click(Sender: TObject);
begin
close;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
IListBox1.AddItem_With_Image(Edit1.Text,nil,GetImageItemIndex);
if IListBox1.Items.Count0 then
begin
IListBox1.ItemIndex:=IListBox1.Items.Count-1;
CurrentItem();
end
else
Edit1.SetFocus;
end;
function TForm1.GetImageItemIndex() : integer;
var
R : integer;
begin
R:=0;
if RB0.Checked then
R:=0;
if RB1.Checked then
R:=1;
if RB2.Checked then
R:=2;
if RB3.Checked then
R:=3;
if RB4.Checked then
R:=4;
if RB5.Checked then
R:=5;
if RB6.Checked then
R:=6;
if RB7.Checked then
R:=7;
if RB8.Checked then
R:=8;
if RB9.Checked then
R:=-1;
Result:=R;
end;
procedure TForm1.Image1Click(Sender: TObject);
begin
RB0.Checked:=true;
end;
procedure TForm1.Image2Click(Sender: TObject);
begin
RB1.Checked:=true;
end;
procedure TForm1.Image3Click(Sender: TObject);
begin
RB2.Checked:=true;
end;
procedure TForm1.Image4Click(Sender: TObject);
begin
RB3.Checked:=true;
end;
procedure TForm1.Image5Click(Sender: TObject);
begin
RB4.Checked:=true;
end;
procedure TForm1.Image6Click(Sender: TObject);
begin
RB5.Checked:=true;
end;
procedure TForm1.Image7Click(Sender: TObject);
begin
RB6.Checked:=true;
end;
procedure TForm1.Image8Click(Sender: TObject);
begin
RB7.Checked:=true;
end;
procedure TForm1.Image9Click(Sender: TObject);
begin
RB8.Checked:=true;
end;
procedure TForm1.Label1Click(Sender: TObject);
begin
RB9.Checked:=true;
end;
procedure TForm1.InsertClick(Sender: TObject);
var
i : integer;
begin
i:=IListBox1.ItemIndex;
if i-1 then
IListBox1.InsertItem_With_Image(i,Edit1.Text,nil,GetImageItemIndex)
else
ShowMessage(' Please Select Bottom item for Insert');
CurrentItem();
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
i : integer;
begin
i:=IListBox1.ItemIndex;
if i-1 then
IListBox1.DeleteItem_With_Image(i)
else
ShowMessage(' Please Select item for Delete');
if IListBox1.Items.Count0 then
begin
IListBox1.ItemIndex:=i-1;
if i-1=-1 then
IListBox1.ItemIndex:=0;
CurrentItem();
end
else
Edit1.SetFocus;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
var
i : integer;
begin
i:=IListBox1.ItemIndex;
if i-1 then
begin
IListBox1.ModifyImage(i,GetImageItemIndex);
IListBox1.Items.Strings[i]:=Edit1.Text;
end
else
ShowMessage(' Please Select item for Modify');
CurrentItem();
end;
procedure TForm1.BitBtn6Click(Sender: TObject);
begin
IListBox1.TabInsert:=not IListBox1.TabInsert;
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
if RadioGroup1.ItemIndex=0 then
IListBox1.BiDiMode:=bdLeftToRight;
if RadioGroup1.ItemIndex=1 then
IListBox1.BiDiMode:=bdRightToLeft;
end;
procedure TForm1.IListBox1KeyPress(Sender: TObject; var Key: Char);
begin
if key=chr(13) then
Edit1.SetFocus;
end;
procedure TForm1.BitBtn5Click(Sender: TObject);
var
Form2 : TForm2;
begin
Form2:=TForm2.Create(nil);
Form2.ShowModal;
Form2.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
IListBox1.AddItem_With_Image('Item1 For Test',nil,1);
end;
end.