没有图像列表的列表视图?

发布于 2025-01-04 08:15:43 字数 1213 浏览 1 评论 0原文

我再次遇到了一个我似乎无法找到解决方案的问题。所以在这里,我有一个显示图像文件目录的ListView,我希望列表视图显示这些文件的这些图像,问题是我还需要程序在每个像素级别修改图像,所以我在单独的线程上完成此操作,所以我想要做的是获取已修改图像的现有 PictureBox 列表,并将文件名称与相应的图像进行匹配。关于如何做到这一点有什么想法吗?

这是我到目前为止所拥有的

public static List<PictureBox> ContentItems = new List<PictureBox>();
...
public static string ContentDirectory = "";

    private void FileTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
    {
        TreeNode newSelected = e.Node;
        FileList.Items.Clear();
        DirectoryInfo nodeDirInfo = (DirectoryInfo)newSelected.Tag;
        ListViewItem.ListViewSubItem[] subItems;
        ListViewItem item = null;

        foreach (FileInfo file in nodeDirInfo.GetFiles())
        {
            item = new ListViewItem(file.Name);
            subItems = new ListViewItem.ListViewSubItem[]
                { new ListViewItem.ListViewSubItem(item, "File"), 
                 new ListViewItem.ListViewSubItem(item, 
                    file.LastAccessTime.ToShortDateString())};

            item.SubItems.AddRange(subItems);
            FileList.Items.Add(item);
        }

        FileList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
    }

once again i have a problem that i can't quite seem to come up with a solution to. so here it is, I have a ListView displaying the directories of Image files,i want the listview to display these images for these files, the problem is I also need the images to be modified by the program at a per-pixel level so i have this done on a separate thread, so what i want to do is take my already existing PictureBox list of the modified Images and match up the names of the files with the corresponding image. Any ideas on how to do this?

here is what i have so far

public static List<PictureBox> ContentItems = new List<PictureBox>();
...
public static string ContentDirectory = "";

    private void FileTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
    {
        TreeNode newSelected = e.Node;
        FileList.Items.Clear();
        DirectoryInfo nodeDirInfo = (DirectoryInfo)newSelected.Tag;
        ListViewItem.ListViewSubItem[] subItems;
        ListViewItem item = null;

        foreach (FileInfo file in nodeDirInfo.GetFiles())
        {
            item = new ListViewItem(file.Name);
            subItems = new ListViewItem.ListViewSubItem[]
                { new ListViewItem.ListViewSubItem(item, "File"), 
                 new ListViewItem.ListViewSubItem(item, 
                    file.LastAccessTime.ToShortDateString())};

            item.SubItems.AddRange(subItems);
            FileList.Items.Add(item);
        }

        FileList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毕竟,我确实必须使用图像列表,这是我如何让它工作的:

    void FileTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
    {
        TreeNode newSelected = e.Node;
        FileList.Items.Clear();
        DirectoryInfo nodeDirInfo = (DirectoryInfo)newSelected.Tag;
        ListViewItem.ListViewSubItem[] subItems;
        ListViewItem item = null;

        ContentImg.Images.Clear();
        int CurrentImg = 0;

        foreach (FileInfo file in nodeDirInfo.GetFiles())
        {
            string fileName = file.Name;
            foreach (PictureBox PB in ContentItems)
            {
                if (fileName == PB.Name)
                {
                    //Get Image
                    ContentImg.Images.Add(PB.Image);

                    item = new ListViewItem(file.Name, CurrentImg);
                    subItems = new ListViewItem.ListViewSubItem[]
                { new ListViewItem.ListViewSubItem(item, "File"), 
                 new ListViewItem.ListViewSubItem(item, 
                    file.LastAccessTime.ToShortDateString())};

                    item.SubItems.AddRange(subItems);
                    FileList.Items.Add(item);
                    CurrentImg += 1;
                }
            }
        }

I Did have to use an image list after all Heres how i got it to work:

    void FileTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
    {
        TreeNode newSelected = e.Node;
        FileList.Items.Clear();
        DirectoryInfo nodeDirInfo = (DirectoryInfo)newSelected.Tag;
        ListViewItem.ListViewSubItem[] subItems;
        ListViewItem item = null;

        ContentImg.Images.Clear();
        int CurrentImg = 0;

        foreach (FileInfo file in nodeDirInfo.GetFiles())
        {
            string fileName = file.Name;
            foreach (PictureBox PB in ContentItems)
            {
                if (fileName == PB.Name)
                {
                    //Get Image
                    ContentImg.Images.Add(PB.Image);

                    item = new ListViewItem(file.Name, CurrentImg);
                    subItems = new ListViewItem.ListViewSubItem[]
                { new ListViewItem.ListViewSubItem(item, "File"), 
                 new ListViewItem.ListViewSubItem(item, 
                    file.LastAccessTime.ToShortDateString())};

                    item.SubItems.AddRange(subItems);
                    FileList.Items.Add(item);
                    CurrentImg += 1;
                }
            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文