VB.net 中的 ObjectListView BarRenderer
ObjectListView BarRenderer in VB.net
我对 ObjectListView 的理解越来越近了。大学习曲线试图将所有示例从 C# 转换为 VB.net。
我创建了一个用于学习目的的工作 ObjectListView。
我正在尝试创建一个基于高度列的 BarRenderer。我最终创建了一个触发 FormatRow 的子程序。但是,当栏显示时,它们并不像预期的那样。我将 Joe 设置为 75,将 Mary 设置为 25。我希望条形图分别充满 75% 和 25%。
可能有一种方法可以像我对 imagegetter 那样做,但我不确定怎么做。我把代码留在那里作为一个额外的例子。
Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
Dim LvLst As New List(Of Person)
Dim LvItm As New Person With {.FirstName = "Joe",
.LastName = "Blow",
.Glasses = "Y",
.Height = "75"}
LvLst.Add(LvItm)
Dim LvItm2 As New Person With {.FirstName = "Mary",
.LastName = "Swanson",
.Glasses = "N",
.Height = "25"}
LvLst.Add(LvItm2)
ObjectListView3.View = View.Details
Dim myImages = New ImageList
myImages.Images.Add(My.Resources.Hipster_Glasses_icon)
myImages.Images.Add(My.Resources.Button_important_icon)
ObjectListView3.SmallImageList = myImages
ObjectListView3.OwnerDraw = True
Col_Glasses.ImageGetter = Function(x As Object) As Integer
Dim casted As Person = DirectCast(x, Person)
If casted.Glasses = "Y" Then
Return 0
Else
Return 1
End If
End Function
ObjectListView3.SetObjects(LvLst)
End Sub
Private Sub lsv_OpenTickets_FormatRow2(sender As Object, e As FormatRowEventArgs) Handles ObjectListView3.FormatRow
Dim tkt As Person = DirectCast(e.Model, Person)
Col_Height.Renderer = New BarRenderer(tkt.Height, 100, Pens.Black, Brushes.Gold)
End Sub
我一直在使用这个网站作为参考:http://objectlistview.sourceforge.net/cs/ownerDraw.html#owner-draw-label
知道了!
我试图将值提供给 BarRenderer,但实际上它会自动读取值。您只需提供条形图的最小值和最大值,它就会创建它。
Col_Height.Renderer = 新 BarRenderer(0, 100, Pens.Black, Brushes.Gold)
事实上,您甚至不需要 FormatRow 事件:
Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
Dim LvLst As New List(Of Person)
Dim LvItm As New Person With {.FirstName = "Joe",
.LastName = "Blow",
.Glasses = "Y",
.Height = "75"}
LvLst.Add(LvItm)
Dim LvItm2 As New Person With {.FirstName = "Mary",
.LastName = "Swanson",
.Glasses = "N",
.Height = "25"}
LvLst.Add(LvItm2)
ObjectListView3.View = View.Details
Dim myImages = New ImageList
myImages.Images.Add(My.Resources.Hipster_Glasses_icon)
myImages.Images.Add(My.Resources.Button_important_icon)
ObjectListView3.SmallImageList = myImages
ObjectListView3.OwnerDraw = True
Col_Glasses.ImageGetter = Function(x As Object) As Integer
Dim casted As Person = DirectCast(x, Person)
If casted.Glasses = "Y" Then
Return 0
Else
Return 1
End If
End Function
Col_Height.Renderer = New BarRenderer(0, 100, Pens.Black, Brushes.Gold)
ObjectListView3.SetObjects(LvLst)
End Sub
我对 ObjectListView 的理解越来越近了。大学习曲线试图将所有示例从 C# 转换为 VB.net。
我创建了一个用于学习目的的工作 ObjectListView。
我正在尝试创建一个基于高度列的 BarRenderer。我最终创建了一个触发 FormatRow 的子程序。但是,当栏显示时,它们并不像预期的那样。我将 Joe 设置为 75,将 Mary 设置为 25。我希望条形图分别充满 75% 和 25%。
可能有一种方法可以像我对 imagegetter 那样做,但我不确定怎么做。我把代码留在那里作为一个额外的例子。
Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
Dim LvLst As New List(Of Person)
Dim LvItm As New Person With {.FirstName = "Joe",
.LastName = "Blow",
.Glasses = "Y",
.Height = "75"}
LvLst.Add(LvItm)
Dim LvItm2 As New Person With {.FirstName = "Mary",
.LastName = "Swanson",
.Glasses = "N",
.Height = "25"}
LvLst.Add(LvItm2)
ObjectListView3.View = View.Details
Dim myImages = New ImageList
myImages.Images.Add(My.Resources.Hipster_Glasses_icon)
myImages.Images.Add(My.Resources.Button_important_icon)
ObjectListView3.SmallImageList = myImages
ObjectListView3.OwnerDraw = True
Col_Glasses.ImageGetter = Function(x As Object) As Integer
Dim casted As Person = DirectCast(x, Person)
If casted.Glasses = "Y" Then
Return 0
Else
Return 1
End If
End Function
ObjectListView3.SetObjects(LvLst)
End Sub
Private Sub lsv_OpenTickets_FormatRow2(sender As Object, e As FormatRowEventArgs) Handles ObjectListView3.FormatRow
Dim tkt As Person = DirectCast(e.Model, Person)
Col_Height.Renderer = New BarRenderer(tkt.Height, 100, Pens.Black, Brushes.Gold)
End Sub
我一直在使用这个网站作为参考:http://objectlistview.sourceforge.net/cs/ownerDraw.html#owner-draw-label
知道了!
我试图将值提供给 BarRenderer,但实际上它会自动读取值。您只需提供条形图的最小值和最大值,它就会创建它。
Col_Height.Renderer = 新 BarRenderer(0, 100, Pens.Black, Brushes.Gold)
事实上,您甚至不需要 FormatRow 事件:
Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
Dim LvLst As New List(Of Person)
Dim LvItm As New Person With {.FirstName = "Joe",
.LastName = "Blow",
.Glasses = "Y",
.Height = "75"}
LvLst.Add(LvItm)
Dim LvItm2 As New Person With {.FirstName = "Mary",
.LastName = "Swanson",
.Glasses = "N",
.Height = "25"}
LvLst.Add(LvItm2)
ObjectListView3.View = View.Details
Dim myImages = New ImageList
myImages.Images.Add(My.Resources.Hipster_Glasses_icon)
myImages.Images.Add(My.Resources.Button_important_icon)
ObjectListView3.SmallImageList = myImages
ObjectListView3.OwnerDraw = True
Col_Glasses.ImageGetter = Function(x As Object) As Integer
Dim casted As Person = DirectCast(x, Person)
If casted.Glasses = "Y" Then
Return 0
Else
Return 1
End If
End Function
Col_Height.Renderer = New BarRenderer(0, 100, Pens.Black, Brushes.Gold)
ObjectListView3.SetObjects(LvLst)
End Sub