Jump to content
Sign in to follow this  
MrGobliN

erro no eleminar de um ficheiro

Recommended Posts

MrGobliN

Boas pessoal, eu estou a desenvolver um projecto de gestao de alunos numa empresa e quando o formulario principal é carregado mostra as informações do aluno e um rectângulo, em que se clica e se introduz la a imagem.

Mas eu se quiser apagar essa imagem para alterar por outra ele da erro e diz que a imagem esta sendo usada, mesmo quando ele não esta a ser utilizada.

Usei este código para apagar a imagem ,mas aparece o erro que esta sendo utilizada:

File.Delete(".\Imagens\" & a & ".png")

Introduzir a imagem (não tem erros):

   Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
 'OpenFileDialog
	Me.OpenFileDialog1.Multiselect = True
	Me.OpenFileDialog1.Title = "Selecionar imagem"
	OpenFileDialog1.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
	'filtra para exibir somente arquivos de imagens
	OpenFileDialog1.Filter = "Images (*.BMP;*.JPG;*.GIF,*.PNG,*.TIFF)|*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF|" & "All files (*.*)|*.*"
	OpenFileDialog1.CheckFileExists = True
	OpenFileDialog1.CheckPathExists = True
	OpenFileDialog1.FilterIndex = 2
	OpenFileDialog1.RestoreDirectory = True
	OpenFileDialog1.ReadOnlyChecked = True
	OpenFileDialog1.ShowReadOnly = True
	Dim dr As DialogResult = Me.OpenFileDialog1.ShowDialog()
	a = IdAlunoTextBox.Text
	If dr = System.Windows.Forms.DialogResult.OK Then
		For Each arquivo As [string] In OpenFileDialog1.FileNames
			Try
				txtArquivo.Items.Add(arquivo)
				File.Copy(arquivo, ".\Imagens\" & a & ".png")
			Catch ex As Exception
				MsgBox("Este aluno ja tem Foto, Apague-a primeiro")
			End Try
		Next
	End If
End Sub

Edited by apocsantos

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.