积极答复者
一组图片怎么用滚动列表的方式显示?

问题
答案
-
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
全部回复
-
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. -
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