TListView Item Focus Theming
When using a TListView and themes are disabled in the Application, the focused and selected item appears something like this:
Notice in both images开发者_如何学运维 where the triangle is. The painted box for the item does not draw where the icon appears. In a TListBox the painted item fills the whole selected item.
How might I be able to get the icon part of the selected item to fill, just as it does with the text part?
I know TListBox renders like this, but I require the use of TListView for the Data property, also the TListView handles icons better via a TImageList.
Thanks.
You'll need to use the OnCustomDraw events of TListView. Within the event handler:
- Determine if the item is selected
- Determine if the control is focused
- Draw the appropriate selection rectangle if the item is selected (grey if the control isn't selected, blue if it is)
- Draw the text
- Draw the image from the imagelist using TImageList.Draw
There are methods for doing these things, such as DrawText and FillRect.
Note that you can use TListBox rather than TListView if you'd rather. You indicated you need the Data property for items in the list, I'd assume to tie them up to your actual model objects. You can do this with anything that supports TStrings (such as TListBox.Items) using TStrings.Objects.
精彩评论