Link to home
Start Free TrialLog in
Avatar of SaLz
SaLz

asked on

Icon in ListBox problem

For one of my other questions, to put an icon in a ListBox, Radikal did this:
https://www.experts-exchange.com/questions/21524774/adding-an-icon-to-the-listbox.html
But when you select an item, the icon loses it's transparent parts, how could i have it so the icon keeps it's transparent parts ?

Thank you,
Sal
Avatar of pcsentinel
pcsentinel

Had a quick look, might need to draw a background, let me check and come back to you
I dont get any issues with images losing quality.
Maybe it is a problem with the images you are using?
Try this instead

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
 with (Control as TListBox) do
  begin
    Canvas.FillRect(Rect);
    Canvas.TextOut(Rect.Left+ImageList1.Height+2,Rect.Top,Items[Index]);
    ImageList1.Draw(Canvas,Rect.Left,Rect.Top,strtoint(Items[Index]));
  end;
end;
Hi!

Ejem...

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with (Control as TListBox) do
  begin
    Canvas.FillRect(Rect);
    Canvas.TextOut(Rect.Left+ImageList1.Height+2,Rect.Top,Items[Index]);
    ImageList1.Draw(Canvas,Rect.Left,Rect.Top,Index);
  end;
end;
Avatar of SaLz

ASKER

Thank you guys, but it doesnt seem to work, it doesnt show any icon ? :/
Test again, load any icon in the imagelist, Ownerdraw to...  
Works perfectly... :)
Avatar of SaLz

ASKER

Nice, forgot about ownerdraw .. ty :)

Btw, is there any way to have two icons next to the text ? I can open this q in new thread :)

Thank you both guys
ASKER CERTIFIED SOLUTION
Avatar of pcsentinel
pcsentinel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SaLz

ASKER

thank you :)