ListBox DrawItem HotLight State in the OwnerDraw mode?

前端 未结 2 1273
萌比男神i
萌比男神i 2021-01-18 07:37

I\'m using OwnerDrawFixed as a DrawMode for the custom ListBox control in my WinForms app.

I want to repaint the background (or do some other action) of

2条回答
  •  隐瞒了意图╮
    2021-01-18 07:59

    This solution will just weigh your code down; just try this:

    If e.State And DrawItemState.Selected Then
                        e.Graphics.FillRectangle(SystemBrushes.HotTrack, e.Bounds)
                        e.Graphics.DrawString(drv, Me.Font, SystemBrushes.HighlightText, e.Bounds.X + 18, e.Bounds.Y + 1)
                    Else
                        e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds)
                        e.Graphics.DrawString(drv, Me.Font, SystemBrushes.ControlText, e.Bounds.X + 18, e.Bounds.Y + 1)
    End If
    

    This operation: e.State And DrawItemState.Selected verifies the item is hovered. No need to put a whole pack of code just to know what item is hovered.

提交回复
热议问题