Home > Net >  C # ListLiew controls loading picture image file repeated problems
C # ListLiew controls loading picture image file repeated problems

Time:04-22

After the first time I save the picture, read the save all files in the folder, displayed on the listview. Second, save the file is stored in the save in the folder for the first time, read all the files, I want to read here many times under the same folder pictures, every time I read the same image is not displayed, convenient after each save pictures, to save the images displayed, folder with the same pictures don't show out

 code: 
SaveFileDialog saveFile;
Private void btn4_Click (object sender, EventArgs e)
{
//save picture
If (pictureBox2. Image==null)
{
MessageBox. Show (" please take good photos ");
return;
}
SaveFile=new SaveFileDialog ();
SaveFile. InitialDirectory=create;
SaveFile. Filter="BMP image file (*. BMP) | *. BMP (*.jpg) | | JPG image file *. JPG | PNG image file (*. PNG) | *. PNG | PPM image files (*. PPM) | *. PPM";
DateTime dt=DateTime. Now;
String name=the string. Format (" {0: yyyyMMddHHmmss} ", dt);
String imgName=name;
SaveFile. FileName=imgName;
If (saveFile. ShowDialog ()==DialogResult. OK)
{
Try
{
PictureBox2. Image. Save (saveFile. FileName);
MessageBox. Show (" file success ");
}
The catch (Exception ex)
{
MessageBox. Show (" file save failed ", "", MessageBoxButtons. OKCancel);
}
}

ListviewGet (Path. GetDirectoryName (saveFile. FileName));
}
The FileInfo [] files;
int k=0;//number
Int m=0;
//ListViewItem item;
List List=new List (a);
///& lt; Summary>
///read the picture displayed in the listview
///& lt;/summary>
///& lt; Param name="path" & gt;
Private void listviewGet (string path)
{
m++;
ListViewItem lv=new ListViewItem ();
DirectoryInfo g=new DirectoryInfo (path);
Files=g.G etFiles ();
The foreach (var item in files)
{
ListView1. Items. The Add (k.T oString (), k);
ListView1. Items [k]. SubItems. Add (item. Name);
ListView1. Items [k]. SubItems. Add (item. FullName);
ListView1. Items [k]. SubItems. Add (item. CreationTime. ToString ());
List. The Add (item. FullName);
K++;

}
}
//double number display picture
Private void listView1_DoubleClick (object sender, EventArgs e)
{
If (listView1. SelectedItems. Count & lt; 0)
{
MessageBox. Show (" no can check item in the list, please add ");
return;
}
PictureBox2. Image=System. Drawing. Image. FromFile (list [listView1. SelectedItems. [0] ImageIndex]);
}
{

Running effect:
Save for the first time:
Second save:
Can see double click on the save for the first time the number is 0 and double-click the second saved number 75 pictures of the two pictures are the same, I think the same images in a listview view shows don't come out
, I know you want to add judgment statements, in the foreach there, but running an old error, as if my statement is wrong, for bosses to reassure yourself!!!!!!
  •  Tags:  
  • C#
  • Related