Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Combobox mit Bitmaps (https://www.delphipraxis.net/104259-combobox-mit-bitmaps.html)

Bomberbb 30. Nov 2007 11:33


Combobox mit Bitmaps
 
Hallo,

Ich will eine Combobox erweitern. Es sollten Bilder vor die Einträge gezeichnet werden. Das wird auch schon gemacht.
Delphi-Quellcode:
Procedure TForm4.TntComboBox1DrawItem(Control : TWinControl;Index : Integer;
  Rect : TRect;State : TOwnerDrawState);
Var
  Bitmap                          : TBitmap;
  Offset                          : Integer;
  Colorloc                        : TColor;
Begin
  offset := 0;
  With TNTComboBox1.Canvas Do
  Begin
    Colorloc := Color;
    FillRect(Rect);
    If tLayer(TNTComboBox1.Items.Objects[index]).IsVisible Then
      Bitmap := Layerlist.BmpLayerOn
    Else
      Bitmap := Layerlist.BmpLayerOff;
    //copy bitmap to combobox coordinate
    BrushCopy(Bounds(Rect.Left +2, Rect.Top , 16, 16), Bitmap, Bounds(0, 0, 16, 16), clred);

    //Set a caption to each item
    Font.size := 10;
    TextOut(Rect.Left + 40, Rect.Top, TNTCombobox1.Items[Index]);

    Brush.Color := tLayer(TNTComboBox1.Items.Objects[index]).GetColor;
    FillRect(Bounds(Rect.Left + 20, Rect.Top + 1, 14, 14));
  End;
End;
Allerdings möchte ich bei einem Klick auf die verschiedenen Elemente eines Items unterschiedliche Sachen ausführen.
Leider habe ich keine Ahnung wie ich herausfinden kann auf welchen Bereich geklickt wurde...

Hat jemand eine Idee???

Reinhardtinho 30. Nov 2007 12:17

Re: Combobox mit Bitmaps
 
Hi,

ich verstehe die Frage nicht ganz, was für Bereiche hast du?

Die Combobox hat dafür nur ein Event "OnChange", wenn ein Eintrag ausgewählt wurde.

Bomberbb 30. Nov 2007 12:24

Re: Combobox mit Bitmaps
 
Ich habe vor jedem Listeneintrag je zwei Bitmaps und will auf einen Klick auf die Bitmap anders reagieren als beim Klick auf den Listeneintrag.

Bernhard Geyer 30. Nov 2007 12:26

Re: Combobox mit Bitmaps
 
Da wirst du dir schon für jeden Eintrag merken müssen wie groß die Bitmap ist und welche x-Bereich sie damit einnimmt.

Bomberbb 30. Nov 2007 12:30

Re: Combobox mit Bitmaps
 
Ja das ist nicht das Problem, aber ich weiß nicht mit welcher Funktion ich das abfangen kann. Es gibt kein onMousedown bei TCombobox.

Tyrael Y. 30. Nov 2007 12:41

Re: Combobox mit Bitmaps
 
OnMouseDown gibt es auch bei TComboBox.

Bei TControl ist das OnMouseDown als protected deklariert.
Mach es public bei deinem Control und go.... ;)

Bomberbb 30. Nov 2007 12:51

Re: Combobox mit Bitmaps
 
Das hab ich auch schon probiert. Das funzt leider auch nur bei dem grauen Feld rechts und nicht bei den Items.

Muetze1 30. Nov 2007 13:04

Re: Combobox mit Bitmaps
 
Und was funktioniert dabei nicht?
Delphi-Quellcode:
...
  published
    property OnMouseDown;
  end;

Deep-Sea 30. Nov 2007 13:06

Re: Combobox mit Bitmaps
 
Ich bezweifel, dass das so einfach geht.
Eine ComboBox ist nun mal nicht dafür gedacht in ihrer DropDown-Liste "Pseudo-Buttons" zu handhaben.

Tyrael Y. 30. Nov 2007 13:10

Re: Combobox mit Bitmaps
 
Wieso sollte es nicht gehen?
Er muss es doch nur verwalten.
Bei OnMouseDown kennt er x und y.
Wenn er in einer ObjectListe feshält, welcher Eintrag welche Daten bekommen hat, kann er anhand davon bestimmen ob er gerade auf einem Bild geklickt hat oder auf den Textbereich.

Ich seh grad nicht wieso das nicht lösbar sein soll.


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:08 Uhr.
Seite 1 von 2  1 2      

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