【发布时间】:2016-09-16 00:44:54
【问题描述】:
我正在 datagridviews 列单元格中绘制图像,如下所示:
Private Sub dataGridView1_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
If e.ColumnIndex = 20 AndAlso e.RowIndex >= 0 Then
If String.IsNullOrEmpty(e.Value.ToString) Then
e.Paint(e.CellBounds, DataGridViewPaintParts.All)
Dim img As Image = Image.FromFile("C:\Users\me\Desktop\glass.png")
e.Graphics.DrawImage(img, e.CellBounds.Left + 10, e.CellBounds.Top + 5, 25, 25)
e.Handled = True
End If
End If
End Sub
如果我将鼠标悬停在其中一个单元格上(仅针对悬停的单元格而不是所有单元格),是否可以将图像切换到另一个?
【问题讨论】:
-
CellEnter(有短暂的延迟?)然后 CellLeave 撤消。不相关,但如果您显示相同的图像或一小组图像,您应该将它们加载到数组或列表中,而不是每次都创建一个新的。每个单元格都需要自己的
glass.png个人副本,您不必担心处理它们。 -
好的,谢谢。所以我假设细胞涂料在进入和离开时会重新发射?
-
不,这不起作用 - 当您激活单元格时会触发。抱歉,我更关注其他花絮
-
CellMouseLeave 和 CellMouseEnter 是我的想法。哎呀.... ^
Every cell does **not** need its own personal copy... -
您能否详细说明将它们加载到数组中的含义?你的意思是不是从文件加载?希望尽可能地优化它。
标签: .net vb.net datagridview