선택한 그림을listview에 표시하고 filename, path, type의 간단한 실례를 표시합니다

1287 단어
 
  
if (openFileDialog1.ShowDialog() == DialogResult.OK)
           {
               listView1.Items.Clear();
               string[] files = openFileDialog1.FileNames; // ,
               string[] fileinfo = new string[3];  // ,
               for (int i = 0; i < files.Length; i++)  //
               {
                   string path = files[i].ToString();  //
                   //
                   string fileName = path.Substring(path.LastIndexOf("\\") + 1, path.Length - 1 - path.LastIndexOf("\\"));
                   //
                   string fileType = fileName.Substring(fileName.LastIndexOf(".") + 1, fileName.Length - 1 - fileName.LastIndexOf("."));
                   fileinfo[0] = fileName;
                   fileinfo[1] = path;
                   fileinfo[2] = fileType;
                   ListViewItem lvi = new ListViewItem(fileinfo);
                   listView1.Items.Add(lvi);

               }
          }

참고: ListView1, View 속성은 Details
OpenFileDialog1, Multiselect 속성은true

좋은 웹페이지 즐겨찾기