
前田稔(Maeda Minoru)の超初心者のプログラム入門


| 
    this.WindowState = FormWindowState.Maximized;
 | 
| 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
    //☆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 Form2()
        {
            InitializeComponent();
            App = new Card(@"c:\data\test\bijin16.jpg", 60, 60);
            timer1.Start();
        }
 | 
| 
        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, 100);
        }
 | 
| 
    public partial class Form1 : Form
    {
        Form2 Anime1 = null;
        private void Button1_Click(object sender, EventArgs e)
        {
            if ((Anime1 == null) || Anime1.IsDisposed)
            {
                this.WindowState = FormWindowState.Minimized;
                Anime1 = new Form2();
                Anime1.Show();
            }
        }
 | 


| 
        public Form3()
        {
            InitializeComponent();
            App = new Card(@"c:\data\test\girl.gif", 128, 216);
            timer1.Start();
        }
 | 
| 
        private void timer1_Tick(object sender, EventArgs e)
        {
            SP_NO = (SP_NO + 1) % 7;
            Invalidate();
        }
 | 
| 
    Form3 Anime2 = null;
    private void Button2_Click(object sender, EventArgs e)
    {
        if ((Anime2 == null) || Anime2.IsDisposed)
        {
            this.WindowState = FormWindowState.Minimized;
            Anime2 = new Form3();
            Anime2.Show();
        }
    }
 | 
