using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Panel panel1; Button button1; PictureBox pictureBox1; Timer timer1; const int startpointX = 50; const int startpointY = 50; const int endpointX = 500; const int endpointY = 50; const int movesizeX = 2; const int movesizeY = 0; private void Form1_Load(object sender, EventArgs e) { this.ClientSize = new Size(800, 600); panel1 = new Panel(); panel1.Dock = DockStyle.Bottom; this.Controls.Add(panel1); button1 = new Button(); button1.Text = "実行"; button1.Click += new EventHandler(button1_Click); panel1.Controls.Add(button1); Bitmap bmp = new Bitmap(100, 100, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(bmp)) { //g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height); g.FillRectangle(Brushes.Transparent, 0, 0, bmp.Width, bmp.Height); //g.SmoothingMode = SmoothingMode.AntiAlias; Pen pen1 = new Pen(Brushes.Red,1); g.DrawEllipse(pen1, 0, 0, 99, 99); pen1.Dispose(); } pictureBox1 = new PictureBox(); pictureBox1.Image = bmp; pictureBox1.Location = new Point(startpointX, startpointY); pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; this.Controls.Add(pictureBox1); timer1 = new Timer(); timer1.Interval = 1000 / 60; timer1.Enabled = false; timer1.Tick += new EventHandler(timer1_Tick); } void timer1_Tick(object sender, EventArgs e) { if (pictureBox1.Location.X >= endpointX) { timer1.Enabled = false; button1.Enabled = true; } else { pictureBox1.Location = new Point(pictureBox1.Location.X + movesizeX, pictureBox1.Location.Y + movesizeY); } } void button1_Click(object sender, EventArgs e) { button1.Enabled = false; pictureBox1.Location = new Point(startpointX, startpointY); timer1.Enabled = true; } } }