06-02-18, 01:40 PM
استخدم DataGridViewImageColumn بدلا من DataGridViewButtonColumn لتستطيع إضافة الصورة بدون كود
هذا الكود لإضافة صورة في العمود الثالت (e.ColumnIndex = 2) عن طريق الحدث CellPainting
هذا الكود لإضافة صورة في العمود الثالت (e.ColumnIndex = 2) عن طريق الحدث CellPainting
PHP كود :
Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
e.Paint(e.CellBounds, DataGridViewPaintParts.All)
If e.RowIndex >= 0 And e.ColumnIndex = 2 Then
Dim wid As Integer = e.CellBounds.Width
Dim hig As Integer = e.CellBounds.Height
Dim img As Image = My.Resources.icon
Dim siz As Size = img.Size
Dim lft As Integer = e.CellBounds.Left + CInt((wid - siz.Width) / 2)
Dim rgt As Integer = e.CellBounds.Top + CInt((hig - siz.Height) / 2)
Dim pnt As New Point(lft, rgt)
e.Graphics.DrawImage(img, New Rectangle(pnt, siz))
End If
e.Handled = True
End Sub

