Hi KailashSahu-8768,
You need to add the image in the file into imageList, and then fill to the listView.
Here is a code example:
private void Form1_Load(object sender, EventArgs e)
{
DirectoryInfo dir = new DirectoryInfo(@"C:\Users\Administrator\Desktop\test");
foreach (FileInfo file in dir.GetFiles())
{
try
{
this.imageList1.Images.Add(Image.FromFile(file.FullName));
}
catch
{
Console.WriteLine("This is not an image file");
}
}
this.listView1.View = View.LargeIcon;
this.imageList1.ImageSize = new Size(32, 32);
this.listView1.LargeImageList = this.imageList1;
//or
//this.listView1.View = View.SmallIcon;
//this.listView1.SmallImageList = this.imageList1;
for (int j = 0; j < this.imageList1.Images.Count; j++)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = j;
this.listView1.Items.Add(item);
}
}
You cannot save all the pictures at once, so you can use the ListView.SelectedIndexChanged event to save the selected picture in the listview to settings.
Settingļ¼
Name:Image1, Type:String, Scope:Application
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
var base64 = string.Empty;
using (MemoryStream ms = new MemoryStream())
{
Image image;
foreach (ListViewItem itm in listView1.SelectedItems)
{
int imgIndex = itm.ImageIndex;
if (imgIndex >= 0 && imgIndex < this.imageList1.Images.Count)
{
image = this.imageList1.Images[imgIndex];
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
base64 = Convert.ToBase64String(ms.ToArray());
Properties.Settings.Default.Image1 = base64;
Properties.Settings.Default.Save();
}
}
}
}
}
>>3:- Run The exe another pc it will run
Could you explain in detail?
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.