资源简介

ListView图片查看小程序(用listview显示某个文件夹中图片为缩略图,picturebox显示大图) 具体的解释写在我的博客(http://blog.csdn.net/frombegintoend/article/details/7705436)

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace ListView2图片副本
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            //MessageBox.Show((GetImages() == null).ToString());
            listView1.View = View.LargeIcon;
            listView1.MultiSelect = false;

            string[] files = GetImages();
            if (files != null)
            {
                ImageList list = GetImage(files);
                if (listView1.LargeImageList == null)
                {
                    listView1.LargeImageList = new ImageList();
                    listView1.LargeImageList.ImageSize = new Size(60 80);
                }
                for (int i = 0; i < list.Images.Count; i++)
                {
                    listView1.LargeImageList.Images.Add(list.Images.Keys[i] list.Images[i]);
                }

                int count = listView1.Items.Count;
                if (files.Length == list.Images.Count)
                {
                    for (int i = count; i < count + files.Length; i++)
                    {
                        int index = i - count;
                        FileInfo info = new FileInfo(files[index]);
                        //ListViewItem item = new ListViewItem(info.Name i);
                        //item.Name = info.FullName;

                        if (!listView1.Items.ContainsKey(files[index]))
                        {
                            listView1.Items.Add(files[index] info.Name i);
                        }
                        else
                        {
                            //listView1.LargeImageList.Images.RemoveByKey(files[index]);//用不着这一句
                            MessageBox.Show(“已存在此图片:“ + files[index] + “,不能重复添加!“);
                        }
                    }
                    //listView1.LargeImageList = list;
                }
            }
        }

        private ImageList GetImage(string[] files)
        {
            ImageList list = new ImageList();
            for (int i = 0; i < files.Length; i++)
            {
                //Image image = Image.FromFile(files[i]);
                list.Images.Add(files[i] Image.FromFile(files[i]));
                list.ImageSize = new Size(60 80);
            }
            return list;
        }

        private string[] GetImages()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Multiselect = true;//设置 选择多个文件
            ofd.InitialDirectory = @“G:\images\“;//设置初始目录  TODO:改为系统默认我的文档中的图片文件夹
            ofd.Multiselect = true;
            //ofd.Filter = “JPG(*.jpg)|*.jpg|JPEG(*.jpeg)|*.jpeg|PNG(

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-06-30 17:51  bin\
     目录           0  2012-06-30 17:51  bin\Debug\
     目录           0  2012-06-30 19:24  bin\Release\
     目录           0  2012-06-30 18:57  bin\Release\app.publish\
     目录           0  2012-06-30 18:57  bin\Release\app.publish\Application Files\
     目录           0  2012-06-30 18:57  bin\Release\app.publish\Application Files\ListView2图片副本_1_0_0_0\
     文件        9728  2012-06-30 18:57  bin\Release\app.publish\Application Files\ListView2图片副本_1_0_0_0\ListView2图片副本.exe.deploy
     文件        7347  2012-06-30 18:57  bin\Release\app.publish\Application Files\ListView2图片副本_1_0_0_0\ListView2图片副本.exe.manifest
     文件        5689  2012-06-30 18:57  bin\Release\app.publish\ListView2图片副本.application
     文件        8805  2012-06-30 18:57  bin\Release\app.publish\publish.htm
     文件      461784  2012-06-30 18:57  bin\Release\app.publish\setup.exe
     文件        1900  2012-06-30 21:11  bin\Release\ListView2图片副本.application
     文件        9728  2012-06-30 21:11  bin\Release\ListView2图片副本.exe
     文件        3642  2012-06-30 21:11  bin\Release\ListView2图片副本.exe.manifest
     文件       26112  2012-06-30 21:11  bin\Release\ListView2图片副本.pdb
     文件        1900  2012-06-30 21:11  bin\Release\ListView2图片副本.vshost.application
     文件       11592  2012-06-30 21:12  bin\Release\ListView2图片副本.vshost.exe
     目录           0  2012-06-30 17:51  obj\
     目录           0  2012-06-30 17:51  obj\Debug\
     目录           0  2012-06-30 17:51  obj\Debug\TempPE\
     目录           0  2012-06-30 21:11  obj\Release\
     文件        1900  2012-06-30 21:11  obj\Release\ListView2图片副本.application
     文件        1628  2012-06-30 21:12  obj\Release\ListView2图片副本.csproj.FileListAbsolute.txt
     文件         847  2012-06-30 18:06  obj\Release\ListView2图片副本.csproj.GenerateResource.Cache
     文件        9728  2012-06-30 21:11  obj\Release\ListView2图片副本.exe
     文件        3642  2012-06-30 21:11  obj\Release\ListView2图片副本.exe.manifest
     文件         180  2012-06-30 21:10  obj\Release\ListView2图片副本.Form1.resources
     文件       26112  2012-06-30 21:11  obj\Release\ListView2图片副本.pdb
     文件         180  2012-06-30 21:10  obj\Release\ListView2图片副本.Properties.Resources.resources
     目录           0  2012-06-30 17:51  obj\Release\TempPE\
     目录           0  2012-06-30 17:51  Properties\
............此处省略12个文件信息

评论

共有 条评论