开发者

ListBoxItem with modified background can't indicate whether its selected?

开发者 https://www.devze.com 2023-03-25 11:21 出处:网络
on a ListBox\'s DrawItem event, I set the background color of each ListBoxItem like so: g.FillRectangle(new SolidBrush(Color.LightYellow), e.Bounds);

on a ListBox's DrawItem event, I set the background color of each ListBoxItem like so:

g.FillRectangle(new SolidBrush(Color.LightYellow), e.Bounds);

The only problem I'm having now, is after I change the background color, I can't tell when a ListBoxItem with a modified background color is selected. In other words, after a ListBoxItem has a modified background color, when I try to select it, its b开发者_运维技巧ackground color doesn't change to blue to indicated it is selected.

How can I have my cake and eat it too, by having my ListBoxItems with modified backgrounds indicate whether they are selected or not too?


You should be inspecting the State member of the DrawItemEventArgs parameter to your handler to determine whether or not the item is selected (or focused, etc.) and then draw the background as you see fit.

This link has a good example of how to do that.

0

精彩评论

暂无评论...
验证码 换一张
取 消