[RESOLVED] picturebox problem
I have this code which creates a picturebox during runtime and displays line graph but I always get an error in this line:
gr1.DrawImage(pic1.Image, -m_Dx, 0) 'it says Value cannot be null. Parameter name: image
code Code:
Public Class Form1
Private Const m_Dx As Single = 1
Dim data As Integer = 1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim pic1 As New PictureBox
pic1.Location = New Point(12, 12)
pic1.Name = "pic1"
pic1.Width = 142
pic1.Height = 102
pic1.Visible = True
pic1.BackColor = Color.Black
pic1.BorderStyle = BorderStyle.Fixed3D
Controls.Add(pic1)
Dim bm1 As New Bitmap(pic1.Width, pic1.Height)
Dim gr1 As Graphics = Graphics.FromImage(bm1)
gr1.DrawImage(pic1.Image, -m_Dx, 0)
gr1.ScaleTransform(1, -101 / pic1.Height)
gr1.TranslateTransform(0, -101)
Dim new_value1 As Integer = Val(data) / 2
If new_value1 < 1 Then new_value1 = 1
gr1.DrawLine(Pens.Blue, _
pic1.Width - 1, 0, _
pic1.Width - 1, new_value1)
For i As Integer = 20 To 80 Step 20
gr1.DrawLine(Pens.Red, pic1.Width - m_Dx, i, pic1.Width, i)
Next i
pic1.Image = bm1
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
data = data + 1
End Sub
End Class
Did I miss something?
Re: [RESOLVED] picturebox problem
You have marked this thread resolved. Please be so considerate next time to add the solution as well. We are all here to help and learn from each other