111,016
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Drawing.Drawing2D;
using System.Diagnostics;
namespace Sample080410
{
public partial class Form1 : Form
{
Bitmap Rectimage = new Bitmap(@"E:\\Rectangle.bmp", true);
Bitmap Triangleimage = new Bitmap(@"E:\\Triangle.bmp", true);
Bitmap Circleimage = new Bitmap(@"E:\\Circle.bmp", true);
int i = 1;
Pen pen = new Pen(Color.Red);
//以下几个point定义无效,实际运行无效果
//Point p1 = new Point(0, 100);
//Point p2 = new Point(700, 100);
//Point p3 = new Point(300, 0);
//Point p4 = new Point(300, 700);
//Point p5 = new Point(100, 0);
//Point p6 = new Point(100, 700);
//Point p7 = new Point(500, 0);
//Point p8 = new Point(500, 700);
int rotate_Y = 100;
int move_Y = 0;
int z = 15;
int trianglemove_Y = 0;
int circlemove_Y = 0;
private System.Windows.Forms.Timer timer1;
public Form1()
{
InitializeComponent();
//下面这行代码是把Form的Load事件绑定为Form1_Load,如果不写这行代码,你要手工将设置
this.Load+=new EventHandler(Form1_Load);
}
private void Form1_Load(object sender, EventArgs e)
{
this.timer1 = new System.Windows.Forms.Timer();
timer1.Tick+=new EventHandler(timer1_Tick);
this.timer1.Interval = 1000;
this.timer1.Enabled = true;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
//在需要重绘窗体的时候,绘制图片,以保持形状,但不移动图片位置
AllPicture(false, e.Graphics);
e.Graphics.Dispose();
}
private void AllPicture(bool movePic,Graphics g)
{
if(g==null)
g = this.CreateGraphics();
//以下四行代码无效因为后面是g.Clear()
//g.DrawLine(pen, p1, p2);
//g.DrawLine(pen, p3, p4);
//g.DrawLine(pen, p5, p6);
//g.DrawLine(pen, p7, p8);
g.Clear(Color.White);
PointF point = new PointF(100, rotate_Y + move_Y);
Matrix Matrix = new Matrix();
Matrix.RotateAt(z, point);
g.Transform = Matrix;
g.DrawImageUnscaled(Rectimage, 50, 50 + move_Y);
if (i % 2 == 0)
{
if (movePic) trianglemove_Y += 1;
PointF pointrotate = new PointF(300, rotate_Y + trianglemove_Y);
Matrix Matrix2 = new Matrix();
Matrix2.RotateAt(z, pointrotate);
g.Transform = Matrix2;
g.DrawImageUnscaled(Triangleimage, 250, 50 + trianglemove_Y);
}
else
{
PointF pointrotate = new PointF(300, rotate_Y + trianglemove_Y);
Matrix Matrix2 = new Matrix();
Matrix2.RotateAt(z, pointrotate);
g.Transform = Matrix2;
g.DrawImageUnscaled(Triangleimage, 250, 50 + trianglemove_Y);
}
if (i % 3 == 0)
{
if (movePic) circlemove_Y += 1;
PointF circlepoint = new PointF(500, rotate_Y + circlemove_Y);
Matrix Matrix3 = new Matrix();
Matrix3.RotateAt(0, circlepoint);
g.Transform = Matrix3;
g.DrawImageUnscaled(Circleimage, 450, 50 + circlemove_Y);
}
else
{
PointF circlepoint = new PointF(500, rotate_Y + circlemove_Y);
Matrix Matrix3 = new Matrix();
Matrix3.RotateAt(0, circlepoint);
g.Transform = Matrix3;
g.DrawImageUnscaled(Circleimage, 450, 50 + circlemove_Y);
}
if (movePic)
{
move_Y += 1;
z += 15;
}
g.Dispose();
if (i < 60)
i++;
else if (i==60)
timer1.Enabled = false;//执行60次,不再使用timer
}
private void timer1_Tick(object sender, EventArgs e)
{
AllPicture(true,null);
}
}
}