## 4个timer实现气泡

4个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 第一周作业
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
    this.BackColor = Color.Red;
    //他的背景颜色是红色   //
    this.FormBorderStyle = FormBorderStyle.None;
    //他是无边框的//
    this.Size = new Size(200,200);
    //他的大小是200长200宽//
    this.Location = new Point(0,0);
    //他的初始位置的坐标是(0.0)点//
    this.Opacity = 0.4;
    //他的不透明程度是0.4//
    GraphicsPath graphics = new GraphicsPath();
    //创建一个GraphicsPath 的对象(实例化)//
    graphics.AddEllipse (0,0,200,200);
    //设置起点为(0.0)点到(200.200)两点的圆//
    this.Region = new Region(graphics);
    //设置与控制关联的窗口区域//
    timer1.Start();
    //开启timer1//
}

private void timer1_Tick(object sender, EventArgs e)
{
    this.Left += 5;
    //宽度以每毫秒5往上增加//
    this.Top  += 5;
    //高度以每毫秒5往上增加//
    if (this.Top +this.Height >=Screen.PrimaryScreen .Bounds .Height )
        //他上边界到窗口上边的距离加上他自身的高度大于等于主屏幕的高度时//
    {
        timer1.Stop();
        //停止timer1//
        timer2.Start ();
        //开启timer2 //
    }
    if (this.Left +this.Width >=Screen.PrimaryScreen.Bounds.Width )
    //他左边界到窗口左边的距离加上他自身的宽度大于等于主屏幕的宽度时//
    {
        timer1.Stop();
        //停止timer1//
        timer4.Start ();
        //开启timer4 //
    }
}

private void timer2_Tick(object sender, EventArgs e)
{
    this.Left += 5;
    //宽度以每毫秒5往上增加//
    this.Top -= 5;
    //高度以每毫秒5往下减少//
    if (this.Left +this.Width >=Screen.PrimaryScreen.Bounds.Width )
    //他左边界到窗口左边的距离加上他自身的宽度大于等于主屏幕的宽度时//
    {
        timer2.Stop();
        //停止timer2//
        timer3.Start();
        //开启timer3 //
    }
    if (this.Top <=0)
    {
        timer2.Stop();
        //停止timer2//
        timer1.Start();
        //开启timer1//
    }
}

private void timer3_Tick(object sender, EventArgs e)
{
    this.Left -= 5;
    //宽度以每毫秒5往上减少//
    this.Top -=10;
    //高度以每毫秒10往下减少//
    if (this.Top <=0)
    {
        timer3.Stop();
        //停止timer3//
        timer4.Start();
        //开启timer4 //
    }
    if (this.Left <=0)
    {
        timer3.Stop();
        //停止timer3//
        timer2.Start();
        //开启timer2 //
    }
}

private void timer4_Tick(object sender, EventArgs e)
{
this.Left -= 5;
//宽度以每毫秒5往下减少//
this.Top += 5;
//高度以每毫秒5往上增加//
if (this.Left <=0)
{
timer4.Stop();
//停止timer4//
timer1.Start();
//开启timer1 //

    }
    if (this.Top +this.Height >=Screen.PrimaryScreen.Bounds.Height )
       // 他上边界到窗口上边的距离加上他自身的高度大于等于主屏幕的高度时//
    {
        timer4.Stop();
        //停止timer4//
        timer3.Start();
        //开启timer3 //
    }
}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
}

总结
计时器 timer
背景颜色 brankcolor
边框设置 FormBorderStyle
初始位置 .Location
边框大小 size
不透明程度 .Opacity
停止计时器 Stop
启用计时器 Start
主屏幕 Screen
宽度 left
高度 top
————————————————
版权声明:本文为CSDN博主「风流倜傥云哥哥」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_45950072/article/details/105442040

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值