1

我发现了 excelsheet 单元格颜色,例如 This is it possible to do this in VB.net Listview ??

在此处输入图像描述

4

1 回答 1

1

您需要编写 ListView.DrawSubitem 事件(MSDN 文档

如果你需要画一些复杂的东西,试着提出一个更具体的问题。

在此处输入图像描述

这是自定义绘制 ListView SubItems 的代码。(创建一个表单,插入一个名为 ListView1 的 Listview 并将 OwnerDraw 属性设置为 True)

对于依赖值的绘图,您将需要使用您的编码技能,祝您好运!!

导入 System.Drawing.Drawing2D

公开课Form2

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

结束类

于 2013-11-12T13:01:55.820 回答