shengrichengxu.txt

来自「自己编写的一个c#的程序,是一个生日程序」· 文本 代码 · 共 93 行

TXT
93 行
字号
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();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?