I have found a way to do it now using a TComboBox and its OnDrawItem event:
1) Set the Style property to csOwnerDrawFixed or csOwnerDrawVariable, this means you will now have to draw each item's output yourself.
2) Populate the combobox items with the filenames of your images, either at design-time in the property editor or at run-time.
3) Use the following code in the OnDrawItem event of the combobox:
Code:
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
combo: TComboBox;
begin
combo := (Control as TComboBox);
combo.Canvas.TextOut(Rect.Left, Rect.Top, combo.Items[Index]);
Image1.Picture.LoadFromFile(combo.Items[Index]);
end;
The 1st line of the method is not essential but aids reading. Therefore, the combo variable declaration can be removed and all references to "combo" can be replaced with "(Control as TComboBox)".
The 2nd line is writing the text for each item onto the drop-down box, you have to do this manually because of the Style setting we made earlier.
The 3rd line loads a TImage component with the item the mouse is currently hovering over. Apparently, the phrase is "hotlighting" an item, but it doesn't seem to be used much.
Hope this helps!
Clive
![[infinity] [infinity] [infinity]](/data/assets/smilies/infinity.gif)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096