none
一组图片怎么用滚动列表的方式显示? RRS feed

  • 问题

  • 请问一组图片怎么用滚动列表的方式显示?

    我现在用的是listview来显示,但listview中每个图片item的size,不能超过256*256.

    我需要用很大的size来显示这些图片。

    请问如何做?

    谢谢了。

    2020年10月7日 8:35

答案

  • Hi BillQu,

    经过我的尝试,你可以尝试下面的代码来根据用户的导入来显示一组图片。

    Code:

      private void Form1_Load(object sender, EventArgs e)
            {
                this.panel1.AutoScroll = true;
            }
    
            int i = 0;
            private void button1_Click(object sender, EventArgs e)
            {
    
                var filePath = string.Empty;
                using (OpenFileDialog openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.InitialDirectory = "D:\\pic";
                    openFileDialog.Filter = "picture files (*.jpg)|*.jpg";
                    openFileDialog.FilterIndex = 2;
                    openFileDialog.RestoreDirectory = true;
    
                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        PictureBox temp = new PictureBox();
                        this.panel1.Controls.Add(temp);
                        temp.SizeMode = PictureBoxSizeMode.StretchImage;
                        string path = openFileDialog.FileName;
                        temp.Image = Image.FromFile(path);
                        temp.Width = 300;
                        temp.Height = 350;
                        temp.BorderStyle = BorderStyle.FixedSingle;
                        temp.Location = new Point(30, 450 * i);
                        i++;
                    }
                }
               
            }

    希望这会对你有用。

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 BillQu0002 2020年10月12日 3:06
    2020年10月9日 1:53
    版主

全部回复

  • Hi BillQu,

    经过我的尝试以及搜索,我发现我们并不能改变size的最大值。

    我下面的代码最后以滚动列表的方式显示:

      private void Form1_Load(object sender, EventArgs e)
            {
                List<Image> list = new List<Image>();
                Image image = null;
                DirectoryInfo dir = new DirectoryInfo(@"D:\pic");
                foreach (FileInfo file in dir.GetFiles("*.jpg"))
                {
                    try
                    {
                        image = Image.FromFile(file.FullName);
                        imageList1.Images.Add(image);
                    }
                    catch
                    {
                        Console.WriteLine("This is not an image file");
                    }
                }
                this.listView1.View = View.LargeIcon;
                this.imageList1.ImageSize = new Size(256, 256);
                this.listView1.LargeImageList = imageList1;
                //or
    
                //this.listView1.View = View.SmallIcon;
                //this.listView1.SmallImageList = this.imageList1;
    
                for (int j = 0; j < imageList1.Images.Count; j++)
                {
                    ListViewItem item = new ListViewItem();
                    item.ImageIndex = j;
                    this.listView1.Items.Add(item);
                }
            }

    效果显示:

    最后,如果你想用很大的size来显示图片,你可以使用panel添加picturebox来显示一组图片。

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2020年10月8日 2:22
    版主
  • 谢谢您的指导。

    我想知道使用panel添加picturebox来显示一组图片该怎么做?

    图片的个数不是固定的,是每次根据用户的选择导入的。

    2020年10月8日 7:13
  • Hi BillQu,

    经过我的尝试,你可以尝试下面的代码来根据用户的导入来显示一组图片。

    Code:

      private void Form1_Load(object sender, EventArgs e)
            {
                this.panel1.AutoScroll = true;
            }
    
            int i = 0;
            private void button1_Click(object sender, EventArgs e)
            {
    
                var filePath = string.Empty;
                using (OpenFileDialog openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.InitialDirectory = "D:\\pic";
                    openFileDialog.Filter = "picture files (*.jpg)|*.jpg";
                    openFileDialog.FilterIndex = 2;
                    openFileDialog.RestoreDirectory = true;
    
                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        PictureBox temp = new PictureBox();
                        this.panel1.Controls.Add(temp);
                        temp.SizeMode = PictureBoxSizeMode.StretchImage;
                        string path = openFileDialog.FileName;
                        temp.Image = Image.FromFile(path);
                        temp.Width = 300;
                        temp.Height = 350;
                        temp.BorderStyle = BorderStyle.FixedSingle;
                        temp.Location = new Point(30, 450 * i);
                        i++;
                    }
                }
               
            }

    希望这会对你有用。

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 BillQu0002 2020年10月12日 3:06
    2020年10月9日 1:53
    版主
  • 非常感谢!

    我先试一试。

    2020年10月9日 6:44