Form1.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace WindowsFormsImageList2
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. private void Form1_Load(object sender, EventArgs e)
  19. {
  20. pictureBox1.Width = 200;
  21. pictureBox1.Height = 165;
  22. string Path = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
  23. Path += @"\01.jpg";
  24. Image img = Image.FromFile(Path, true);
  25. imageList1.Images.Add(img);
  26. imageList1.ImageSize = new Size(200, 165);
  27. }
  28. private void button1_Click(object sender, EventArgs e)
  29. {
  30. if (imageList1.Images.Count == 0)
  31. {
  32. MessageBox.Show("没有图像");
  33. }
  34. else
  35. {
  36. pictureBox1.Image = imageList1.Images[0];
  37. }
  38. }
  39. private void button2_Click(object sender, EventArgs e)
  40. {
  41. imageList1.Images.RemoveAt(0);
  42. pictureBox1.Image = null;
  43. }
  44. }
  45. }