AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Bilder in einer Combobox

Ein Thema von Luckie · begonnen am 30. Jan 2003
Antwort Antwort
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#1

Bilder in einer Combobox

  Alt 30. Jan 2003, 23:33
Delphi-Quellcode:
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;
Gefunden in einem Beitrag von Luckie.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Antwort Antwort

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:18 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz