/***************************************/
/*★ 背景画像をスクロール 前田 稔 ★*/
/***************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
public static Bitmap Back;
public int Pos;
private Timer timer1;
private System.ComponentModel.IContainer components;
// Constructor
public MyForm()
{
// timer1
components = new System.ComponentModel.Container();
timer1 = new System.Windows.Forms.Timer(this.components);
SuspendLayout();
timer1.Interval = 15;
timer1.Tick += new System.EventHandler(this.timer1_Tick);
// MyForm
this.Width = 640;
this.Height = 480;
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
Paint += new PaintEventHandler(MyHandler);
Pos = 0;
timer1.Start();
}
// 画像を描画
private void MyHandler(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(Back,new Rectangle(0,0,640,480),
new Rectangle(Pos,0,640,480),GraphicsUnit.Pixel);
}
private void timer1_Tick(object sender, EventArgs e)
{
Pos =(Pos+1)%640;
Invalidate();
}
}
class form01
{
public static void Main()
{
// Load Image
try
{ MyForm.Back= new Bitmap(@"c:\data\test\utyu.jpg"); }
catch
{ MessageBox.Show("イメージが取得できません", "Error");
return;
}
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|