C#.NET之窗体应用程序四个Timer实现气泡

C#.NET之窗体应用程序四个Timer实现气泡_第1张图片

在这里插入代码片
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace 弹窗
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Random rad = new Random();

        private void Form1_Load(object sender, EventArgs e)
        {
            this.FormBorderStyle = FormBorderStyle.None;
            this.Size = new Size(200, 200);
            GraphicsPath path = new GraphicsPath();
            path.AddEllipse(0,0,this.Width,this.Height);
            this.Region = new Region(path);
            this.BackColor = Color.Red;
            this.Opacity = 0.7;
            this.Location = new Point(0,0);
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Left += 6;
            this.Top += 6;
            if (this.Top+this.Height>=Screen.PrimaryScreen.Bounds.Height)
            {
                this.BackColor = Color.FromArgb(rad.Next(255), rad.Next(255), rad.Next(255));
                timer1.Stop();
                timer2.Start();
            }
            if (this.Left+this.Width>=Screen.PrimaryScreen.Bounds.Width)
            {
                this.BackColor = Color.FromArgb(rad.Next(255), rad.Next(255), rad.Next(255));
                timer1.Stop();
                timer3.Start();
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Left += 6;
            this.Top -= 6;
            if (Top<=0)
            {
                this.BackColor = Color.FromArgb(rad.Next(255), rad.Next(255), rad.Next(255));
                timer2.Stop();
                timer1.Start();
            }
            if (this.Left + this.Width >= Screen.PrimaryScreen.Bounds.Width)
            {
                this.BackColor = Color.FromArgb(rad.Next(255), rad.Next(255), rad.Next(255));
                timer2.Stop();
                timer3.Start();
            }
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            this.Left -= 6;
            this.Top += 6;
            if (this.Top + this.Height >= Screen.PrimaryScreen.Bounds.Height)
            {
                this.BackColor = Color.FromArgb(rad.Next(255), rad.Next(255), rad.Next(255));
                timer3.Stop();
                timer4.Start();
            }
            if (this.Left<=0)
            {
                this.BackColor = Color.FromArgb(rad.Next(255), rad.Next(255), rad.Next(255));
                timer3.Stop();
                timer2.Start();
            }
        }

        private void timer4_Tick(object sender, EventArgs e)
        {
            this.Left -= 6;
            this.Top -= 6;
            if (Top<=0)
            {
                this.BackColor = Color.FromArgb(rad.Next(255), rad.Next(255), rad.Next(255));
                timer4.Stop();
                timer3.Start();
            }
            if (this.Left <= 0)
            {
                this.BackColor = Color.FromArgb(rad.Next(255), rad.Next(255), rad.Next(255));
                timer4.Stop();
                timer2.Start();
            }
        }
    }
}



你可能感兴趣的:(C#.NET之窗体应用程序四个Timer实现气泡)