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;
namespace 高级控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i = 0;
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// int i = 0;
string path = openFileDialog1.FileName;
Image image = Image.FromFile(path,true);
imageList1.Images.Add(image);
pictureBox1.Image = imageList1.Images[i];
i++;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (imageList1.Images.Count > 0)
{
if (imageList1.Images.Count > 1)
{
if(i>=imageList1.Images.Count)
{
i=0;
}
imageList1.Images.RemoveAt(i);
pictureBox1.Image=imageList1.Images[i];
MessageBox.Show("已删除图片");
}
else
{
imageList1.Images.RemoveAt(i);
pictureBox1.Image=null;
MessageBox.Show("已删除全部图片");
}
}
else
{
MessageBox.Show("已删除全部图片,无图片可删");
}
}
private void button3_Click(object sender, EventArgs e)
{
if (i >= imageList1.Images.Count)
{
i = 0;
}
pictureBox1.Image=imageList1.Images[i++];
}
}
}