cscの作法 その55


概要

cscの作法、調べてみた。
走る人やってみた。

写真

サンプルコード

using System;
using System.Windows.Forms;
using System.Drawing;

class form1: Form {
	PictureBox pb0;
	Image img;
	int ind;
	form1() {
		Text = "WebBrowser";
		ClientSize = new Size(420, 320);
		pb0 = new PictureBox();
		pb0.Width = 85;
		pb0.Height = 102;
		img = Image.FromFile("sprite-animation4.png");
		pb0.Image = img;
		ind = 0;
		Controls.AddRange(new Control[] {
			pb0
		});
		Timer timer = new Timer();
		timer.Interval = 100; 
		timer.Tick += new EventHandler(timerTick);
		timer.Start();
	}
	void timerTick(object sender, EventArgs e) {
		int x;
		int y;
		Text = DateTime.Now.ToString("HH:mm:ss");
		ind = ind + 1;
		if (ind > 29) 
			ind = 0;
		x = (ind % 6) * 85;
		y = (ind / 6) * 102;
		Bitmap canvas = new Bitmap(pb0.Width, pb0.Height);
		Graphics g = Graphics.FromImage(canvas);
		Rectangle srcRect = new Rectangle(x, y, 85, 102);
		Rectangle desRect = new Rectangle(0, 0, srcRect.Width, srcRect.Height);
		g.DrawImage(img, desRect, srcRect, GraphicsUnit.Pixel);
		g.Dispose();
		pb0.Image = canvas;
		this.Invalidate();
	}
	[STAThread]
	public static void Main() {
		Application.Run(new form1());
	}
}




以上。