I am trying to draw something on a Picturebox and save the drawing with the PB.Image.Save.
But I get the shown near the end of the following code.
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Text
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
PB.Refresh()
End Sub
Private Sub PB_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)Handles PB.Paint
Dim g As Graphics = e.Graphics
' Draw a string on the PictureBox.
g.DrawString("This is a diagonal line drawn on the control", _
New Font("Arial", 10), Brushes.Red, New PointF(30.0F, 30.0F))
' Draw a line in the PictureBox.
g.DrawLine(System.Drawing.Pens.Red, PB.Left, PB.Top, PB.Right, PB.Bottom)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PB.Image.Save("C:\B-52\Test.jpg", Imaging.ImageFormat.Jpeg)
' It dies HERE with the following error message:
' NullReferenceException was unhandled
' Object reference not set to an instance of an objece.
' Tip: Use the "new" keyword to create an object instance.
End Sub
End Class
What is the "Null Reference" referring to?
With what do I use the "new" keyword?
Any suggestions will be appreciated.
But I get the shown near the end of the following code.
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Text
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
PB.Refresh()
End Sub
Private Sub PB_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)Handles PB.Paint
Dim g As Graphics = e.Graphics
' Draw a string on the PictureBox.
g.DrawString("This is a diagonal line drawn on the control", _
New Font("Arial", 10), Brushes.Red, New PointF(30.0F, 30.0F))
' Draw a line in the PictureBox.
g.DrawLine(System.Drawing.Pens.Red, PB.Left, PB.Top, PB.Right, PB.Bottom)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PB.Image.Save("C:\B-52\Test.jpg", Imaging.ImageFormat.Jpeg)
' It dies HERE with the following error message:
' NullReferenceException was unhandled
' Object reference not set to an instance of an objece.
' Tip: Use the "new" keyword to create an object instance.
End Sub
End Class
What is the "Null Reference" referring to?
With what do I use the "new" keyword?
Any suggestions will be appreciated.