R
Robin Tucker
Hi ppl,
My owner draw list box controls do not "refresh" old selected items when a
new selection is made. This means that as you click to make selections, the
previously selected items stay highlighted along with the new ones too. It
draws correctly when I minimize the window and then maximise it again, but I
just don't seem to be getting a "DrawItem" event for switching of an item
from Selected to NotSelected! Any ideas???
Here is the code I use:
Private Sub ListBox_DrawItem(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles ListBox.DrawItem
' Guard
If e.Index < 0 Then
Exit Sub
End If
' Get the object we wish to draw
Dim theItem As DataThumbnailViewItem = CType(ListBox.Items()(e.Index),
DataThumbnailViewItem)
' and render it.
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
theItem.Render(e.Graphics, e.Bounds, True)
Else
theItem.Render(e.Graphics, e.Bounds, False)
End If
End Sub
and the code in the DataThumbnailViewItem render is something like:
' If selected, draw box border in selected colour
If bIsSelected Then
theGraphics.FillRectangle(System.Drawing.SystemBrushes.Highlight,
theBounds)
Else
theGraphics.FillRectangle(System.Drawing.SystemBrushes.Window,
theBounds)
End If
My owner draw list box controls do not "refresh" old selected items when a
new selection is made. This means that as you click to make selections, the
previously selected items stay highlighted along with the new ones too. It
draws correctly when I minimize the window and then maximise it again, but I
just don't seem to be getting a "DrawItem" event for switching of an item
from Selected to NotSelected! Any ideas???
Here is the code I use:
Private Sub ListBox_DrawItem(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles ListBox.DrawItem
' Guard
If e.Index < 0 Then
Exit Sub
End If
' Get the object we wish to draw
Dim theItem As DataThumbnailViewItem = CType(ListBox.Items()(e.Index),
DataThumbnailViewItem)
' and render it.
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
theItem.Render(e.Graphics, e.Bounds, True)
Else
theItem.Render(e.Graphics, e.Bounds, False)
End If
End Sub
and the code in the DataThumbnailViewItem render is something like:
' If selected, draw box border in selected colour
If bIsSelected Then
theGraphics.FillRectangle(System.Drawing.SystemBrushes.Highlight,
theBounds)
Else
theGraphics.FillRectangle(System.Drawing.SystemBrushes.Window,
theBounds)
End If