Greetings. The situation is this: there are several forms; on one of the forms, pictures with fabrics are dynamically loaded. in the process, you can remove one of the pictures. implemented this way - if you click on the picture, a new form will fly out with the same larger picture and the delete button. when you click on it, the name of the picture is entered into a separate class and when the form is closed it is loaded into Main_FormClosed . Code :
try { string CompletePatchToEXE = Directory.GetCurrentDirectory(); DirectoryInfo dir = new DirectoryInfo(CompletePatchToEXE + @"\\materials\\"); string delNAME = OrderData.deletFiles[0].ToString() + ".jpg"; foreach (FileInfo file in dir.GetFiles()) { if (file.Name == delNAME) { file.Delete(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } And the problem is that the specified file is still used by the application and cannot delete it. How to be, tell me? Thank.
Image files are dynamically loaded from the @ "materials /" directory and assigned as background images for picchers like this:
PB.BackgroundImage = Image.FromFile("materials/" + ListName[i] + ".jpg");
using ( File f = File.Open()) {};- nick_n_astatic void DoDeleteFiles() { try { .... file.Delete } }and sostatic Image DoLoadImage(string filename) { return Image.FromFile(filename); }static Image DoLoadImage(string filename) { return Image.FromFile(filename); }- nick_n_a