c# - Save the state of a form with PictureBox? -


i have small program in winforms; it's program can have pictures, have problem. when have picture, close program , open again, pictures don't stay have put them, in picturebox.

more simply, want keep state when close program, saving.

here code :

public partial class form2 : form {     public form2()     {         initializecomponent();     }                private void picturebox1_click(object sender, eventargs e)         {             openfiledialog f = new openfiledialog();             f.showdialog();               var chemin = f.filename;             picturebox1.imagelocation = chemin;          }      } } 

please me, can't go on problem...

the simplest way use application settings. right-click on project , select properties. go settings. in right hand side, see panel grid 1 line. change setting in name column imagelocation , leave other 3 values (type, scope , value) defaults (string, user , blank).

in design view of form under properties double-click formclosing event create new handler. enter:

        if (picturebox1.imagelocation != null)         {             properties.settings.default.imagelocation = picturebox1.imagelocation;             properties.settings.default.save();         } 

finally in constructor form enter following after initializecomponent():

        if (properties.settings.default.imagelocation != null)         {             picturebox1.imagelocation = properties.settings.default.imagelocation;         } 

hth


Comments