我有一个自定义的listview控件,它向用户显示通知列表。基本上,当一个新的通知出现时,一个新的条目将被添加到Bold的listview中。当用户读取通知时,它会变成常规字体。
我唯一能找到实现这个目标的方法可能是(读取状态),那就是使用复选框。因此,一个新的通知将被检查它的项目,当它被读取时,它被取消检查。这是很好的工作,似乎实现了我的需要。
然而,我的问题is....is有一种方法,我可以删除绘图的复选框,但仍然保持在后台的功能。因此,例如,不为listview项绘制复选框,但仍然能够使用ListView.Checkboxes = True和ListViewItem.Checked = True?
我的ListView控件是所有者绘制的,我的DrawItem事件的代码如下所示:
Protected Overrides Sub OnDrawItem(e As DrawListViewItemEventArgs)
Try
If Not (e.State And ListViewItemStates.Selected) = 0 Then
'Draw the background for a selected item.
e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Highlight, e.Bounds)
e.DrawFocusRectangle()
Else
'Draw the background for an unselected item.
e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Control, e.Bounds)
End If
e.DrawBackground()
e.DrawDefault = True
MyBase.OnDrawItem(e)
Catch ex As Exception
MsgBox("Exception Error: " & ex.Message, MsgBoxStyle.Critical, "Module: lsvOverdueCalls_DrawItem()")
End Try
End Sub如果删除e.DrawDefault = True,它会删除复选框,但是我无法控制新通知的粗体字体。
任何帮助都很感激。谢谢
发布于 2014-04-28 05:31:56
最后,我通过创建一个新的ListViewItem类来解决这个问题,这个类继承了ListViewItem,然后添加了一个自定义属性。然后,在整个代码中引用一个ListViewItem时,我使用了新的类,这允许我向默认的ListViewItem添加一个新属性。
Public Class cust_ListViewItem
Inherits ListViewItem
Private _read As Boolean
Private RegularFont As New Font(Me.Font.FontFamily, Me.Font.size, FontStyle.Regular)
Private BoldFont As New Font(Me.Font.FontFamily, Me.Font.size, FontStyle.Bold)
Public Property Read As Boolean
Get
Return _read
End Get
Set(value As Boolean)
_read = value
MarkAsRead()
End Set
End Property
Private Sub MarkAsRead()
If _read Then Me.Font = RegularFont Else Me.Font = BoldFont
End Sub
End Class然后,为了调用我的新属性,我使用了以下方法:
Dim lvi As cust_ListViewItem = New cust_ListViewItem
If Notifications(x).Read = True Then
lvi.Read = True
...但是,我还发现了下面的Link,它允许您从单个列表查看项中完全删除复选框,这正是我最初试图实现的目标。我刚刚将代码添加到我的自定义listview类中,并将代码应用于每个listview项。
https://stackoverflow.com/questions/23305002
复制相似问题