I have a Form that loads its default BgImage from a subfolder at the location of my application.
When the default BackgroundImage is visible, it can be used as a drop area for other common bitmap formats(drag and drop image from Windows Explorer).
If there are any images in the subfolder, the image which is at the first position in the folder will be loaded as the default BackgroundImage.
string path = (full path to folder here, @"image_default\");
string[] anyfirstimage = Directory.GetFiles(path);
if (String.IsNullOrEmpty(anyfirstimage[0]))
{
// do nothing
}
else
{
this.BackgroundImage = Image.FromFile(anyfirstimage[0]);
}
How could I improve the above code, so that I don't get an exception 'Index bounds outside the array'
when the subfolder contains no images?
Instead of getting an exception error in this case - is there a way for the next image drag and drop into that area to copy it into the subfolder automatically as the new default image,
every time the Form runs and there are no images in the subfolder?