0

我有一个DataGridView带有一个按钮的列。当我将以下代码与图像一起使用unblock3.png时,会显示图像,但是当我将其替换为另一个图像时,check1.png什么都不会显示。

我尝试将大小调整check1.png为更小的尺寸,但它仍然无法正常工作。

你能帮我找出问题所在吗?

Private Sub ShiftsList_CellPainting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles ShiftsList.CellPainting
    If ShiftsList.Columns(e.ColumnIndex).Name = "ConfirmShift" AndAlso e.RowIndex >= 0 Then
        e.Paint(e.CellBounds, DataGridViewPaintParts.All)
        e.Graphics.DrawImage(My.Resources.unblock3, CInt((e.CellBounds.Width / 2) - (My.Resources.unblock3.Width / 2)) + e.CellBounds.X, CInt((e.CellBounds.Height / 2) - (My.Resources.unblock3.Height / 2)) + e.CellBounds.Y)
        e.Handled = True
    End If
End Sub

资源文件夹

未选中

已检查

4

1 回答 1

1

我认为图像已显示,但太小以至于人眼无法识别。

我唯一需要添加的是为 draw 命令提供所需的宽度和高度。

If FilesList.Columns(e.ColumnIndex).Name = "Unblock" AndAlso e.RowIndex >= 0 Then
        e.Paint(e.CellBounds, DataGridViewPaintParts.All)
        e.Graphics.DrawImage(My.Resources.unblock3, CInt((e.CellBounds.Width / 2) - (My.Resources.unblock3.Width / 2)) + e.CellBounds.X, CInt((e.CellBounds.Height / 2) - (My.Resources.unblock3.Height / 2)) + e.CellBounds.Y, My.Resources.unblock3.Width, My.Resources.unblock3.Height)
        e.Handled = True
    End If

我的图片很小,只有 32x32,所以我提供了它们的原始尺寸。

在此处输入图像描述

于 2016-03-24T19:54:52.983 回答