Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27189

Drawing on Picturebox (via bitmap & graphics) - works only FIRST time

$
0
0
Hello all,

when I run the code bellow first time, all is crispy (picturebox gets bitmap with vector graphics painted on it, it lasts, can be saved to file). However, when I try to load second file (execute the same ReadFile_Click() sub with different vector data), the PictureBox turns BLANK.
I can't figure out, why it works only first time and what should be cleared/disposed/refreshed/etc to get it working...
(code stripped of unnecessary parts):

Code:


       
picturebox Code:

       
  1. Public Bitmap1 As Bitmap
  2.     Public picture1 As Graphics
  3.  
  4.     Private Sub ReadFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReadFile.Click
  5.         ' CLEARING
  6.         Me.DataGridView1.Rows.Clear()
  7.         'Me.PictureBox1.Image = Nothing
  8.         picture1 = Nothing
  9.         Bitmap1 = Nothing
  10.         ' INICIALIZATION
  11.         Bitmap1 = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
  12.         picture1 = Graphics.FromImage(Bitmap1)
  13.    
  14.         Call Redraw()
  15.     End Sub
  16.  
  17.     Public Sub Redraw()
  18.         Call ComputeScale()
  19.         Call PlotAllVectorData()
  20.         Me.PictureBox1.Image = Bitmap1
  21.     End Sub


During execution of PlotAllVectorData(), it is (via few subs) painted onto the picturebox, roughly like this:
Code:

Me.picture1.DrawLine(objPen,X,Y,X1,Y1)
I spent a lot of time on it and googling it, still can't figure it out. I'd appriciate your suggestions.

Best regards,

Oak

Viewing all articles
Browse latest Browse all 27189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>