ok so I have multiple PictureBoxes and when I press the single button "save" I want all PictureBoxes to save at once. Below is the code I currently have, but Visual Basic keeps coming back with the error "check to see if the object is null before calling the method" on line 6 (end of first "end if" statement_.
I realise there's also an issue with the MessageBox statement and I could always take it out entirely. My Main concern is the null statement. I'm very new with Visual Basic and coding and feel I've got to be close on this.
I realise there's also an issue with the MessageBox statement and I could always take it out entirely. My Main concern is the null statement. I'm very new with Visual Basic and coding and feel I've got to be close on this.
PHP Code:
Private Sub ButtonSave_Click(sender As Object, e As EventArgs) Handles ButtonSave.Click
For Each pb As PictureBox In GroupBoxKiosk101Side1.Controls.OfType(Of PictureBox)()
If pb.Image Is Nothing Then
Call Me.CreateDefaultImageinPB(pb)
MessageBox.Show("Not all images are uploaded", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
Using PictureBox As Image = New Bitmap(pb.Image)
Using Stream As New IO.MemoryStream
PictureBox.Save(Stream, Imaging.ImageFormat.Jpeg)
cmd.Parameters.Add("@image", SqlDbType.VarBinary).Value = Stream.GetBuffer()
End Using
End Using
Next
end sub
Private Sub CreateDefaultImageinPB(_PictureBox As PictureBox)
_PictureBox.Image = New Bitmap(_PictureBox.Width, _PictureBox.Height)
Dim graphics As Graphics = graphics.FromImage(_PictureBox.Image)
Dim brush As Brush = New SolidBrush(Color.White)
graphics.FillRectangle(brush, New System.Drawing.Rectangle(0, 0, _PictureBox.Width, _PictureBox.Height))
End Sub