Board index » delphi » Help - Need enhancement to TCustomlistbox
john.greening
![]() Delphi Developer |
Fri, 17 Jan 2003 03:00:00 GMT
|
john.greening
![]() Delphi Developer |
Fri, 17 Jan 2003 03:00:00 GMT
Help - Need enhancement to TCustomlistbox
I need a listbox where I can set the font attributes differently for each
item in the list. Ideally I'd also like to store 'other' information again for each item, but that is not displayed on the control. Any helpful ideas appreciated. John. |
AlanGLLo
![]() Delphi Developer |
Fri, 17 Jan 2003 03:00:00 GMT
Re:Help - Need enhancement to TCustomlistboxIn article <3985c92...@news1.vip.uk.com>, "john.greening" Quote<john.green...@tinyonline.co.uk> writes: you to do this. You select the font in that event handler appropriately, maybe using a set to hold the indices of the items of any one font and then set that font for the canvas. Declare the sets containing appropriate index values :- type const Set the TListBox.Style to lbOwnerDrawFixed Then code the OnDrawItem event handler :- procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Ideally I'd also like to store 'other' information again Quote>for each item, but that is not displayed on the control. integer) value. This is typed as a TObject and can be one, or it can be typecast to any integer or Dword value. So it can be a pointer to a string (or PChar), but you have to allocate the memory before use, and free it after use. To store an integer ListBox1.Items.AddObject('This Item', TObject(12345)); or to add or change a stored integer :- ListBox1.Items.Objects[3] := 765432; . . . and to retrieve it :- MyInteger := integer(ListBox1.Items.Objects[3]); To store an object (eg a TForm) :- ListBox1.Items.Objects[3] :=Form2; // no type-cast needed - it is a TObject .. and use it in the OnClick event handler :- With ListBox1 do To store a colour which you might use for colouring the text :- ListBox1.Items.Objects[2] := TObject(clRed); . . . and to retrieve it :- MyColor := TColor(ListBox1.Items.Objects[2]); Alan Lloyd |
Neil J. Rubenki
![]() Delphi Developer |
Sat, 18 Jan 2003 03:00:00 GMT
Re:Help - Need enhancement to TCustomlistboxIn article <3985c92...@news1.vip.uk.com>, john.green...@tinyonline.co.uk says... Quote> Any helpful ideas appreciated. substantially different from each other, you may want to set the Style to lbOwnerDrawVariable and respond to OnMeasureItem, to set the height of each item. You can use the API function DrawText() with the DT_CALCRECT flag to calculate the smallest rectangle that will fit the text, then add a few pixels to the height. -- Neil J. Rubenking Contributing Technical Editor PC Magazine |
john.greenin
![]() Delphi Developer |
Sat, 18 Jan 2003 03:00:00 GMT
Re:Help - Need enhancement to TCustomlistboxthanks guys, this is most appreciated. I'm still learning and this type of reply aids my understanding significantly. John. |
Jim O'Brie
![]() Delphi Developer |
Sun, 19 Jan 2003 03:00:00 GMT
Re:Help - Need enhancement to TCustomlistboxQuoteIn article <3985c92...@news1.vip.uk.com>, John.greening wrote: E.g., if you put in a given item "item 5\this is some extra information" you could arrange to paint only the "item 5" and the rest could be anything you like. This avoids goofing around with the Objects[] array if you'd prefer not to. -- |
Neil J. Rubenki
![]() Delphi Developer |
Sun, 19 Jan 2003 03:00:00 GMT
Re:Help - Need enhancement to TCustomlistboxIn article <VA.0000001e.051d7...@remove-this-prefix.unitoops.com>, unito...@remove-this-prefix.unitoops.com says... Quote> This avoids goofing around with the Objects[] array if you'd prefer not excellent activity! It's incredibly convenient, being able to create a tiny TObject descendant to hold any information at all that's associated with the listbox items. Ditto with the Data member of treeview and listview nodes. I just had to speak up in favor of those handy features. -- Neil J. Rubenking Contributing Technical Editor PC Magazine |
Bruce Robert
![]() Delphi Developer |
Sun, 19 Jan 2003 03:00:00 GMT
Re:Help - Need enhancement to TCustomlistbox"Neil J. Rubenking" <jrube...@SPAM-B-GONE.mother.com> wrote in message Quote> In article <VA.0000001e.051d7...@remove-this-prefix.unitoops.com>, associating objects with entries and also quite handy for storing any 4 byte value that relates to entries, including record pointers. |
Jim O'Brie
![]() Delphi Developer |
Mon, 20 Jan 2003 03:00:00 GMT
Re:Help - Need enhancement to TCustomlistboxIn article <MPG.13f1c1fec2d371e7989...@news.mother.com>, Neil J. Rubenking wrote: Quote> But... but... but... "goofing around" with the Objects array is an I agree with you - it's a great facility. However, it does impose a Regards, Jim. P.S. It's been a long time - how are you doing? -- |