Autor Beitrag
mcbrunox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 92



BeitragVerfasst: Sa 22.02.03 06:10 
hat wer Erfahrung mit dieser komponente. die gibts bei torry
man kann damit listboxen mit bildern machen,aber ich komm nicht weiter weil er immer nur das 1'ste bild sprich das bild in index 0 anzeigt(TImaglist),obwohl ich mehr drinnen hab.

Komischerweise passiert mir das bei anderen Komponenten auch dieser Art. Also liegts wieder mal am dummen programmierer. Kann mir jemand bescheid geben, falls jener weis was ich falsch mache ? thX
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 22.02.03 06:12 
Wenn es dir nur um Bildchen in der Listbox geht, dazu brauchst du keine Komponente, das geht auch so:

ausblenden volle Höhe Quelltext
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:
//This code works also with TListBox 

var
  Bitmap1, Bitmap2, Bitmap3, Bitmap4: TBitmap; 
... 
procedure TForm1.FormCreate(Sender: TObject);
begin
  ComboBox1.Style:=csOwnerDrawVariable; 
  //Set height of one item 
  ComboBox1.ItemHeight:=20; 
  //load all bitmaps 
  Bitmap1 := TBitmap.Create;
  Bitmap1.LoadFromFile('chem16.bmp'); 
  Bitmap2 := TBitmap.Create;
  Bitmap2.LoadFromFile('chip16.bmp'); 
  Bitmap3 := TBitmap.Create;
  Bitmap3.LoadFromFile('factry16.bmp'); 
  Bitmap4 := TBitmap.Create;
  Bitmap4.LoadFromFile('skylin16.bmp'); 
  //assign bitmaps with item objects - caption of the items: Bitmap 1 - Bitmap 4 
  ComboBox1.Items.AddObject('Bitmap 1', Bitmap1);
  ComboBox1.Items.AddObject('Bitmap 2', Bitmap2);
  ComboBox1.Items.AddObject('Bitmap 3', Bitmap3);
  ComboBox1.Items.AddObject('Bitmap 4', Bitmap4);
end; 
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  Bitmap: TBitmap;
  Offset: Integer;
begin
  offset:=0;
  with ComboBox1.Canvas do
  begin
    FillRect(Rect);
    Bitmap := TBitmap(ComboBox1.Items.Objects[index]);
    if Bitmap <> nil then
    begin
      //copy bitmap to combobox coordinate 
      BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width,
      Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width,
      Bitmap.Height), clred);
      Offset := Bitmap.width + 8;
    end;
    //Set a caption to each item 
    TextOut(Rect.Left + Offset, Rect.Top, Combobox1.Items[Index]);
  end;
end; 
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  //free all bitmap objects 
  bitmap1.Free;
  bitmap2.Free;
  bitmap3.Free;
  bitmap4.Free;
end;
mcbrunox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 92



BeitragVerfasst: Sa 22.02.03 06:21 
ja aber ich möchte die items verschieben auch können,und das ist mir bei dieser codegrundlage doch etwas zu steil.
mit ner kompo gehts noch einfach<da hab ich schon alles programmiert ausser das alle bilder in der listbox gleich aussehen, was eigentlich nicht sein sollte. dort häng ich halt...