I’m Trying to use event datagridview RowPostPaint but output image in row header becomes blurry and there is a white color on each side of the in image with vb.net.
If you look at the screenhot, the result of a good image appears in the picturebox, how can I have the same result as the picturebox. Or something is wrong with my code.
Please Guide me
Thanks
Public Class Form1
Private _source As New BindingSource()
Private _person As List(Of person) = Nothing
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
_person = New List(Of person)()
_person.Add(New person With {
.ID = 1,
.Name = "Tridip"
})
_person.Add(New person With {
.ID = 2,
.Name = "Sujit"
})
_person.Add(New person With {
.ID = 3,
.Name = "Arijit"
})
_source.DataSource = _person
DataGridView1.DataSource = _source
End Sub
Private Sub DataGridView1_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
'Convert the image to icon, in order to load it in the row header column
Dim myBitmap As New Bitmap(imageList1.Images(0))
Dim myIcon As Icon = Icon.FromHandle(myBitmap.GetHicon())
Dim graphics As Graphics = e.Graphics
'Set Image dimension - User's choice
Dim iconHeight As Integer = 20
Dim iconWidth As Integer = 20
'Set x/y position - As the center of the RowHeaderCell
Dim xPosition As Integer = e.RowBounds.X + (DataGridView1.RowHeadersWidth / 2)
Dim yPosition As Integer = e.RowBounds.Y + ((DataGridView1.Rows(e.RowIndex).Height - iconHeight) 2)
Dim rectangle As New Rectangle(xPosition, yPosition, iconWidth, iconHeight)
graphics.DrawIcon(myIcon, rectangle)
End Sub
End Class
Public Class person
Public Property ID As Integer
Public Property Name As String
End Class