/***************************************/
/*★ Double Buffer を使う 前田 稔 ★*/
/***************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
private Timer timer1;
private System.ComponentModel.IContainer components;
public static Bitmap bmp;
int SP_NO;
public MyForm()
{
// timer1
components = new System.ComponentModel.Container();
timer1 = new System.Windows.Forms.Timer(this.components);
SuspendLayout();
timer1.Interval = 200;
timer1.Tick += new System.EventHandler(this.timer1_Tick);
// MyForm
Name = "MyForm";
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SP_NO = 0;
timer1.Start();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawImage(bmp,new Rectangle(80,10,128,216),
new Rectangle(SP_NO*128,0,128,216),GraphicsUnit.Pixel);
}
private void timer1_Tick(object sender, EventArgs e)
{
SP_NO= (SP_NO+1)%7;
Invalidate();
}
}
class anime
{
public static void Main()
{
// Load Image
try
{
MyForm.bmp= new Bitmap("c:\\data\\test\\girl.gif");
}
catch
{ MessageBox.Show("イメージが取得できません", "Error");
return;
}
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|