Salut tout le monde
Svp j'ai besoin d'aide pour resoudre ce probleme
Dans ma Form1 j'ai une PictureBox1 .. et ce code complet :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Imports System.IO
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.PictureBox1.Image = Image.FromFile(Application.StartupPath & "\FolderBackground\Background.Png")
    End Sub
    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
        Dim ofd As New OpenFileDialog
        With ofd
            ofd.AddExtension = True
            ofd.CheckPathExists = True
            ofd.CheckFileExists = True
            ofd.Filter = "Choose Image (*.PNG; *.JPG; *.GIF; *.JPEG)| *.PNG; *.JPG; *.GIF; *.JPEG | All Files (*.*)|*.*"
            ofd.FilterIndex = 4
            ofd.Multiselect = False
            If .ShowDialog = DialogResult.OK Then
                Dim ms As New MemoryStream()
                Dim bmpImage As New Bitmap(Image.FromFile(ofd.FileName))
                bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
                Me.PictureBox1.Image = Image.FromStream(ms)
                bmpImage.Dispose()
            End If
        End With
 
        If Me.PictureBox1.Image Is Nothing Then
            MessageBox.Show("Veuillez sélectionner une image avant d'enregistrer", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
            Exit Sub
        End If
 
        If IO.Directory.Exists(Application.StartupPath & "\FolderBackground\Background.Png") = False Then
            IO.Directory.CreateDirectory(Application.StartupPath & "\FolderBackground")
        End If
 
        Me.PictureBox1.Image.Save(Application.StartupPath & "\FolderBackground\" & "\" & "Background" + ".Png")
        MessageBox.Show("L'image a été enregistrée dans le dossier du projet et remplacée par l'image d'origine", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
 
    End Sub
End Class
Mon probleme c'est lorsque j'arret cette ligne dans ma Form1 Load
Code : Sélectionner tout - Visualiser dans une fenêtre à part
Me.PictureBox1.Image = Image.FromFile(Application.StartupPath & "\FolderBackground\Background.Png")
Tout marche d'une facon magnifique .. et l'image s'enregistrera et sera remplacee par l'ancienne l'image dans mon dossier ( FolderBackground )
Et lorsque je laisse cette ligne fonctionne dans ma Form1 Load alors quand j'essaye par PictureBox1 Click de changer et choisir une autre image je recevrai cet erreur comme l'indique ce photo
Nom : 1.png
Affichages : 218
Taille : 83,6 Ko
Merci beaucoup d'avance pour l'aide
Cordialement
MADA