
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
//☆ Card Object Class
class Card
{
public Bitmap bmp;
public int W; //Sprite の幅
public int H; //Sprite の高さ
public int N; //横の枚数
// Constructor
public Card(string file, int w, int h)
{
try
{ bmp = new Bitmap(file); }
catch
{
MessageBox.Show("イメージが取得できません", "Error");
return;
}
W = w;
H = h;
N = bmp.Width / w;
}
// 画像全体を描画
public void View(Graphics g, int x, int y)
{
if (bmp != null) g.DrawImage(bmp, x, y);
}
// Sprite を描画
public void View(Graphics g, int n, int x, int y)
{
Rectangle des = new Rectangle(x, y, W, H);
Rectangle sou = new Rectangle((n % N) * W, (n / N) * H, W, H);
if (bmp != null)
g.DrawImage(bmp, des, sou, GraphicsUnit.Pixel);
}
}
|
Card App;
int SP_NO = 0;
public Form1()
{ InitializeComponent();
App = new Card(@"c:\data\test\bijin16.jpg", 60, 60);
}
|
private void MyHandler(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
if (App.bmp == null) Application.Exit();
App.View(g, 20, 20);
}
|
![]()
int SP_NO = 0;
private void timer1_Tick(object sender, EventArgs e)
{ SP_NO= (SP_NO+1)%16;
Invalidate();
}
|
private void MyHandler(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
if (App.bmp == null) Application.Exit();
App.View(g, SP_NO, 20, 20);
}
|
public Form1()
{ InitializeComponent();
App = new Card(@"c:\data\test\bijin16.jpg", 60, 60);
timer1.Start();
}
|
![]()