Question Picturebox shows error after picturebox.image = nothing

altf1

New member
Joined
Aug 6, 2010
Messages
1
Programming Experience
Beginner
For the example I've 1 picturebox and 1 button :
Private Sub pbFoto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbFoto.Click
'Mengobservasi ekstensi dari file gambar
tnpGambar = 1
'Refresh()
pbFoto.Show()
Try
OFD.Filter = "Image Files (*.JPEG, *.jpg, *.bmp, *.gif, *.png)|*.JPEG; *.jpg; *.bmp; *.gif; *.png"

If OFD.ShowDialog() = DialogResult.OK Then
pbFoto.Update()
namaGbr = OFD.FileName
Dim Gbrbaru As New Bitmap(namaGbr)
pbFoto.SizeMode = PictureBoxSizeMode.StretchImage
pbFoto.Image = Image.FromFile(namaGbr.ToString)

End If

'OFD = Nothing
Catch ae As System.ArgumentException
namaGbr = " "
MsgBox("Program error " _
& vbCrLf & Err.Description)
MyConnection.close()
Catch ex As Exception
MsgBox("Program error " _
& vbCrLf & Err.Description)
MyConnection.close()
End Try
End Sub

Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click
Try
Masukan_Nonaktif()
Navigasi_Aktif()

namaGbr = ""
mProses = ""
mProses2 = ""
btnTambah.BackgroundImage = CType(resources.GetObject("btnTambah.BackgroundImage"), System.Drawing.Image)
btnTambah.Enabled = True

btnHapus.BackgroundImage = CType(resources.GetObject("btnHapus.BackgroundImage"), System.Drawing.Image)
btnHapus.Enabled = True

btnUbah.BackgroundImage = CType(resources.GetObject("btnUbah.BackgroundImage"), System.Drawing.Image)
btnUbah.Enabled = True

btnCari.BackgroundImage = CType(resources.GetObject("btnCari.BackgroundImage"), System.Drawing.Image)
btnCari.Enabled = True

btnSimpan.BackgroundImage = CType(resources.GetObject("btnSimpan.BackgroundImage"), System.Drawing.Image)
btnSimpan.Enabled = False

bersih()

If pbFoto.Image IsNot Nothing Then

pbFoto.Image.Dispose()
File.Delete("image.jpg")
pbFoto.Image = Nothing
pbFoto.Refresh()

End If

lblSimpan.Text = "Simpan (Ctrl + S)"

Catch ex As Exception
MsgBox("Program error " _
& vbCrLf & Err.Description)
MyConnection.close()
End Try
'Tampildata()
End Sub


after I click button btnRefresh then the program shows:
attempted to read or write protected memory.this is often an indication that other memory is corrupt

how to solve this?
thanks
 
Back
Top