Windows 屏幕气泡代码四个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;
using System.Drawing.Drawing2D;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None;
this.Size = new Size(200, 200);
this.BackColor = Color.Green;
this.Opacity = 0.8;
this.Location = new Point(0, 0);
GraphicsPath path = new GraphicsPath();
path.AddEllipse(0,0,this.Width,this.Height);
this.Region = new Region(path);
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.Top += 3;
this.Left += 3;
if (this.Top+this.Height>=Screen.PrimaryScreen.Bounds.Height)
{
timer1.Stop();
timer2.Start();
}
if (this.Left+this.Width>=Screen.PrimaryScreen.Bounds.Width)
{
timer1.Stop();
timer3.Start();
}
}
private void timer2_Tick(object sender, EventArgs e)
{
this.Left += 3;
this.Top -= 3;
if (this.Top<=0)
{
timer2.Stop();
timer1.Start();
}
}
private void timer3_Tick(object sender, EventArgs e)
{
this.Left -= 3;
this.Top += 3;
if (this.Top+this.Height>=Screen.PrimaryScreen.Bounds.Height)
{
timer3.Stop();
timer4.Start();
}
}
private void timer4_Tick(object sender, EventArgs e)
{
this.Left -= 3;
this.Top -= 3;
if (this.Top <= 0)
{
timer4.Stop();
timer1.Start();
}
}
}
}
最终效果