C#实现气泡屏保(四个timer实现)

四个timer实现气泡屏保

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;

namespace 四个timer实现气泡屏保
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //实例化一个对象
        Label lb = new Label();
        Timer time1 = new Timer();
        Timer time2 = new Timer();
        Timer time3 = new Timer();
        Timer time4 = new Timer();
        private void Form1_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
            this.FormBorderStyle = FormBorderStyle.None;
            lb.Text = "易烊千玺A爆了";
            lb.Font = new Font("宋体",40);
            lb.AutoSize = true;
            this.Controls.Add(lb);

            time1.Interval = 2;
            time1.Tick += Time1_Tick;
            time1.Start();

            time2.Interval = 2;
            time2.Tick += Time2_Tick;

            time3.Interval = 2;
            time3.Tick += Time3_Tick;

            time4.Interval = 2;
            time4.Tick += Time4_Tick;
        }
        private void Time1_Tick(object sender, EventArgs e)
        {
            lb.Left = lb.Left + 5;
            lb.Top = lb.Top + 5;
            if (lb.Top + lb.Height >= Screen.PrimaryScreen.WorkingArea.Height)
            {
                time1.Stop();
                time2.Start();
            }
            if (lb.Left+lb.Width>=Screen.PrimaryScreen.Bounds.Width)
            {
                time1.Stop();
                time4.Start();
            }
        }
        private void Time2_Tick(object sender, EventArgs e)
        {
            lb.Left = lb.Left + 5;
            lb.Top = lb.Top - 5;
            if (lb.Left+lb.Width>=Screen.PrimaryScreen.Bounds.Width)
            {
                time2.Stop();
                time3.Start();
            }
            if (lb.Top<=0)
            {
                time2.Stop();
                time1.Start();
            }
        }
        private void Time3_Tick(object sender, EventArgs e)
        {
            lb.Left = lb.Left - 5;
            lb.Top = lb.Top - 5;
            if (lb.Top<=0)
            {
                time3.Stop();
                time4.Start();
            }
            if (lb.Left<=0)
            {
                time3.Stop();
                time2.Start();
            }
        }
        private void Time4_Tick(object sender, EventArgs e)
        {
            lb.Left = lb.Left - 5;
            lb.Top = lb.Top + 5;
            if (lb.Left<=0)
            {
                time4.Stop();
                time1.Start();
            }
            if (lb.Top+lb.Height>=Screen.PrimaryScreen.WorkingArea.Height)
            {
                time4.Stop();
                time3.Start();
            }
        }
    }
}

你可能感兴趣的:(C#实现气泡屏保(四个timer实现))