/**************************************************/
/*★ 画像を分割して ImageList に登録 前田 稔 ★*/
/**************************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
class MyForm : Form
{
Bitmap bijin;
ImageList imglist;
Bitmap[] sp_bijin = new Bitmap[16];
Graphics graphics;
int SP_NO;
public MyForm()
{
try
{ bijin = new Bitmap("c:\\data\\test\\bijin16.jpg"); }
catch
{ MessageBox.Show("画像ファイルが読めません!");
return ;
}
imglist = new ImageList();
imglist.ImageSize = new Size(60, 60);
for(int i=0; i<16; i++)
{ sp_bijin[i] = new Bitmap(60,60);
graphics = Graphics.FromImage(sp_bijin[i]);
graphics.DrawImage(bijin,new Rectangle(0,0,60,60),
new Rectangle(60*(i%4),60*(i/4),60,60),GraphicsUnit.Pixel);
imglist.Images.Add(sp_bijin[i]);
}
Paint += new PaintEventHandler(MyHandler);
MouseDown += new MouseEventHandler(OnMyMouseDown);
SP_NO = 0;
}
private void MyHandler(object sender, PaintEventArgs e)
{
imglist.Draw(e.Graphics, 60, 60, SP_NO);
}
private void OnMyMouseDown(object sender, MouseEventArgs e)
{
SP_NO= (SP_NO+1)%16;
Invalidate();
}
}
class form01
{ public static void Main()
{ MyForm mf = new MyForm();
Application.Run(mf);
}
}
|