|
楼主 |
发表于 2007-10-11 23:22:07
|
显示全部楼层
原帖由 ks453187387 于 2007-10-11 23:19 发表
多学一门小技巧 不错
对不起,我还没传代码。
- //这就帖
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Text;
- using System.Windows.Forms;
- namespace HappyBirthdayToMe
- {
- public partial class Form1 : Form
- {
- Point p;
- Random r;
- int f;
- Color[] color = { Color.Green,Color.Blue,
- Color.Red,Color.Yellow,
- Color.YellowGreen,
- Color.Tomato,
- Color.PowderBlue
- };
- public Form1()
- {
- InitializeComponent();
- r = new Random();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- p.X += 5;
- p.Y += 5;
- this.Location = p;
- if (this.Location.Y >= 150 && this.Location.X >= 300)
- {
- this.timer1.Stop();
- this.timer2.Start();
- f = r.Next(0, 7);
- this.button1.ForeColor = color[f];
- }
- }
- private void timer2_Tick(object sender, EventArgs e)
- {
- p.X -= 5;
- p.Y += 5;
- this.Location = p;
- if (this.Location.Y >= 300 && this.Location.X <= 150)
- {
- this.timer2.Stop();
- this.timer3.Start();
- f = r.Next(0, 7);
- this.button1.ForeColor = color[f];
- }
- }
- private void timer3_Tick(object sender, EventArgs e)
- {
- p.X -= 5;
- p.Y -= 5;
- this.Location = p;
- if (this.Location.Y <= 150 && this.Location.X <= 100)
- {
- this.timer3.Stop();
- this.timer4.Start();
- f = r.Next(0, 7);
- this.button1.ForeColor = color[f];
- }
- }
- private void timer4_Tick(object sender, EventArgs e)
- {
- p.X += 5;
- p.Y -= 5;
- this.Location = p;
- if (this.Location.Y <= 100 && this.Location.X >= 150)
- {
- this.timer4.Stop();
- this.timer1.Start();
- f = r.Next(0, 7);
- this.button1.ForeColor = color[f];
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- this.timer1.Stop();
- this.timer2.Stop();
- this.timer3.Stop();
- this.timer4.Stop();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- p = new Point(150, 100);
- this.Location = p;
- this.timer1.Start();
- }
- }
- }
复制代码
本来想用GDI画的但是好难处理重绘问题,后来改了 |
|