public partial class Form1 : Form {
private MyImages images;
public Form1() {
InitializeComponent();
images = new MyImages();
}
private void pictureBox1_Click(object sender, EventArgs e) {
images.MoveNext();
pictureBox1.Image=new Bitmap(images.Current);
}
}
public class MyImages : IEnumerator<string> {
private string[] images;
private int i = -1;
public MyImages() {
images = new string[] {
@"e:\flotspe\pictures\funny-pictures-cat-tells-you-to-kiss-his-bottom.jpg",
@"E:\flotspe\pictures\funny-pictures-fighting-cats-constructive-feedback.jpg",
@"E:\flotspe\pictures\funny-pictures-kitten-crashed-laptop.jpg",
@"E:\flotspe\pictures\funny-pictures-scared-cat-naked-guy.jpg"
};
}
public string Current {
get {
if (i == -1) throw new InvalidOperationException();
if (images == null) throw new ObjectDisposedException("MyImages");
return images[i];
}
}
public void Dispose() {
images = null;
}
object System.Collections.IEnumerator.Current {
get { return Current; }
}
public bool MoveNext() {
i++;
if (i == images.Length) i = 0;
return true;
}
public void Reset() {
i = -1; ;
}
}