using System;
using System.Drawing;
using System.Windows.Forms;
namespace AnimationTest3a
{
public class Form1 : Form
{
Timer timer1;
PictureBox pictureBox1;//PictureBox
Panel panel1;//Panel
Bitmap canvas;
int x = 0;
int y = 20;
const int radius = 50;
Brush bg_brush = new SolidBrush(SystemColors.Control);
Brush fg_brush = new SolidBrush(Color.Black);
System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null)) components.Dispose();
base.Dispose(disposing);
}
public Form1()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
timer1 = new Timer();
timer1.Interval = 20;
timer1.Tick += timer1_Tick;
pictureBox1 = new PictureBox();//PictureBox
panel1 = new Panel();//Panel
this.Controls.Add(pictureBox1); this.Controls.Add(panel1);
this.ClientSize = new Size(600, 400);
pictureBox1.Size = new Size(600, 200);
pictureBox1.BorderStyle = BorderStyle.FixedSingle;
panel1.Size = new Size(600, 200);
panel1.Location = new Point(0, 200);
canvas = new Bitmap(600, 200);
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
Graphics g = Graphics.FromImage(canvas);
int x2 = x + 2;
g.FillRectangle(fg_brush, x2, y, radius, radius);
g.FillRectangle(bg_brush, x, y, x2 - x, radius);
x = x2;
g.Dispose();
pictureBox1.Image = new Bitmap(canvas);//PictureBox
panel1.BackgroundImage = new Bitmap(canvas);
if (x > 550)
{
x = 0; x2 = 0;
canvas = new Bitmap(600, 200);
}
timer1.Enabled = true;
}
}
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}