/*★ Counter Class でカウントする 前田 稔 ★*/
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
private System.ComponentModel.IContainer components;
private Timer timer1;
private Counter Cls = new Counter("num12.gif", 12);
private int CNT;
public MyForm()
{
InitializeComponent();
Paint += new PaintEventHandler(MyHandler);
CNT = 90;
timer1.Start();
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
this.timer1.Interval = 500;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
this.ClientSize = new System.Drawing.Size(300, 200);
this.Name = "MyForm";
this.ResumeLayout(false);
}
private void MyHandler(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Cls.View(g, CNT, 100, 50);
}
private void timer1_Tick(object sender, EventArgs e)
{
CNT++;
Invalidate();
}
}
class form01
{
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
class Counter
{ public Bitmap m_bmp;
public int m_width;
public Counter(string ImgFile, int width)
{ m_width= width;
try
{ m_bmp= new Bitmap(ImgFile); }
catch
{ MessageBox.Show("イメージが取得できません", "Error");
Environment.Exit(-1); //プログラムの終了
}
}
public void View(Graphics g, int num, int x, int y)
{ int n,p,i;
for(n=num,i=0; i<6; i++)
{ p= n%10;
n= n/10;
g.DrawImage(m_bmp, new Rectangle((6-i)*m_width+x,y,m_width,m_width),
new Rectangle(p*m_width,0,m_width,m_width),GraphicsUnit.Pixel);
}
}
}
|