2016-03-24 37 views
0

我有一個按鈕列的datagridview。當我使用帶有圖像「unblock3.png」的follwing代碼時,會顯示圖像,但是當我用另一個圖像「check1.png」替換它時,不顯示任何內容。Datagridview按鈕列未在油漆上顯示圖像VB.NET

我嘗試將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 

enter image description here

png

enter image description here

回答

0

我認爲這是顯示的圖像,但太小了人眼識別。

我需要添加的唯一東西是提供具有所需寬度和高度的繪圖命令。

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小,所以我提供了他們的原始尺寸。

enter image description here