I am working on the migration of a GIS program. The original code is written in VB6 and uses gdi32 lib. The new code is written in VB.Net. I have rewritten all the code excepting for the GIS-specific algorithms. I don't think it is a good idea to understand and migrate these algorithms because they have been developed and tested since 1988. So I decided to work around using PInvoke:
Gdi32.Polygon(hdc, lpPoint, nCount)
In Gdi32 class:
<DllImport("gdi32.dll")> _
Friend Shared Function Polygon(ByVal hdc As Integer, ByRef lpPoint As Object, ByVal nCount As Integer) As Integer
End Function
To get hdc, I was doing this:
hdc = MyPictureBox.CreateGraphics().GetHdc
So far so good. But then I learned that drawing directly on the PictureBox control is not a good idea because it is not persistent. Now I want to draw my polygons in a Bitmap and then set this bitmap as the Image property of PictureBox:
hdc = Graphics.FromImage(MyBitmap).GetHdc()
[...] 'Draw the polygons
MyPictureBox.Image = MyBitmap
But this doesn't seem to work. Nothing is shown on the PictureBox. Any ideas?
Thank you :)