この本読んで勉強中。しっかし理屈が詳しく書いてないのでちょっとわかり辛いけど、じっくりと読むと、どのコードがどうしているのかが分かってきてかなり面白い。
今やってるコード
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Image plane1;
private void Form1_Load(object sender, EventArgs e)
{
Text = "Plane FLY!";
Width = 550; Height = 400;
Left = (Screen.PrimaryScreen.Bounds.Width - Width) / 2;
Top = (Screen.PrimaryScreen.Bounds.Height - Height) / 2;
BackColor = Color.Gray;
plane1 = Image.FromFile("Plane.gif");
pictureBox1.Image = Image.FromFile("plane.gif");
pictureBox1.BackColor = Color.Gray;
pictureBox1.Left = 10;
pictureBox1.Top = 50;
pictureBox1.Visible = false;
button1.SetBounds(200, 320, 62, 31);
button2.SetBounds(300, 320, 62, 31);
}
private void button1_Click(object sender, EventArgs e)
{
Graphics gp = pictureBox1.CreateGraphics();
timer1.Interval = 200;
timer1.Enabled = true;
timer2.Interval = 200;
timer2.Enabled = true;
pictureBox1.Visible = true;
gp.Dispose();
}
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Left += 10;
if(pictureBox1.Left > Width) {
pictureBox1.Left = 10;
}
}
bool flag = true;
private void button2_Click(object sender, EventArgs e)
{
flag = !flag;
if (flag == true)
{
pictureBox1.Visible = true;
}
else
{
pictureBox1.Visible = false;
}
}
int px = 10, py = 100;
int oldpx = 10;
private void timer2_Tick(object sender, EventArgs e)
{
Graphics g = CreateGraphics();
g.FillRectangle(Brushes.Cyan, oldpx, py, plane1.Width, plane1.Height);
if (px > 550)
{
px = -10;
}
px += 10;
oldpx = px;
g.DrawImage(plane1, new Rectangle(px, py, plane1.Width, plane1.Height));
g.Dispose();
}
}
}
0 件のコメント:
コメントを投稿