[英]Changing Listview Subitems colors
I found excelsheet cell colors like This is it possible to do this in VB.net Listview ?? 我发现像这样的excelsheet单元格颜色这可以在VB.net Listview中完成吗?
You need to code the ListView.DrawSubitem Event ( MSDN Documentation ) 您需要对ListView.DrawSubitem事件进行编码( MSDN文档 )
If you need to draw something complex, try to make a more specific question. 如果您需要绘制复杂的东西,请尝试提出更具体的问题。
Here is the code for custom draw ListView SubItems. 这是自定义绘制ListView子项的代码。 (Create a form, insert a Listview called ListView1 and set the OwnerDraw property to True)
(创建一个窗体,插入一个名为ListView1的Listview并将OwnerDraw属性设置为True)
For the value-dependant drawing, you will need to use your coding skills, get lucky !! 对于价值依赖的图纸,您将需要使用您的编码技巧,所以很幸运!
Imports System.Drawing.Drawing2D 导入System.Drawing.Drawing2D
Public Class Form2 公开课表格2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim itmX As ListViewItem
For iRow As Integer = 0 To 10
itmX = ListView1.Items.Add(iRow.ToString, iRow.ToString, "")
For iCol As Integer = 1 To 3
itmX.SubItems.Add(iCol.ToString)
Next
Next
End Sub
Private Sub ListView1_DrawColumnHeader(sender As Object, e As DrawListViewColumnHeaderEventArgs) Handles ListView1.DrawColumnHeader
e.DrawDefault = True
End Sub
Private Sub ListView1_DrawItem(sender As Object, e As DrawListViewItemEventArgs) Handles ListView1.DrawItem
'e.DrawDefault = True
End Sub
Private Sub ListView1_DrawSubItem(sender As Object, e As DrawListViewSubItemEventArgs) Handles ListView1.DrawSubItem
Dim rnd As New Random(Now.TimeOfDay.Milliseconds)
Dim r As Integer = rnd.Next(0, 255)
Dim g As Integer = rnd.Next(0, 255)
Dim b As Integer = rnd.Next(0, 255)
Using br As New LinearGradientBrush(New Point(0, e.Bounds.Height / 2), New Point(e.Bounds.Width, e.Bounds.Height / 2), Color.FromArgb(255, r, g, b), Color.Transparent)
e.Graphics.FillRectangle(br, e.SubItem.Bounds)
e.Graphics.DrawRectangle(Pens.Black, e.SubItem.Bounds)
e.DrawText()
End Using
End Sub
End Class 末级
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.