Voilà un petit exemple qui change de page toutes les secondes :
(en supposant que tu fais du Windows Forms)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
class Form1 : Form
{
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
PictureBox _pictureBox;
Timer _timer;
int _currentPage = 0;
public Form1()
{
_pictureBox = new PictureBox();
_pictureBox.Dock = DockStyle.Fill;
_pictureBox.Image = Image.FromFile(@"E:\tmp\bomb.tif");
this.Controls.Add(_pictureBox);
_timer = new Timer();
_timer.Interval = 1000;
_timer.Tick += _timer_Tick;
_timer.Start();
}
void _timer_Tick(object sender, EventArgs e)
{
int pageCount = _pictureBox.Image.GetFrameCount(FrameDimension.Page);
_currentPage = (_currentPage + 1) % pageCount;
_pictureBox.Image.SelectActiveFrame(FrameDimension.Page, _currentPage);
_pictureBox.Invalidate();
}
} |
En gros, les points importants sont les suivants :
- la méthode GetFrameCount renvoie le nombre de frames pour une dimension donnée (en l'occurrence, les pages)
- la méthode SelectActiveFrame permet de choisir une frame pour une dimension donnée
- la méthode Invalidate rafraichit la PictureBox pour afficher la nouvelle page sélectionnée
Partager