如何实现一个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;
//想用GraphicsPath必须先引用//
using System.IO;

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.6;
        //他的不透明度为百分之60//
        GraphicsPath path = new GraphicsPath();
        //创建一个GraphicsPath类型,实例化//
        path.AddEllipse(0, 0, this.Width, this.Height);
       //因为path是创建属于的class,并且有自己的输入方法//
        this.Region = new Region(path);
        //关联一个窗口,region属于GraphicsPath//
        timer1.Start();
        //启用计时器timer1//

    }
    int x = 8;
    //定义一个变量x=//
    int y = 5;
   //定义一个变量y=5//
    private void timer1_Tick(object sender, EventArgs e)

    {
        this.Left += x;
        //他的宽度每经过0.1毫秒增加x//
        this.Top += y;
        //他的高度每经过0.1毫秒增加y**
        if (this.Top+this.Height >=Screen.PrimaryScreen.Bounds .Height ||Top <=0)
            //如果满足他上边到主屏幕的距离加上他自生的高度大于等于屏幕的高度或者他的高度小于等于主屏幕的高度时//
        {
            y = -y;
            //y就等于负y
            Form1 f1 = new Form1();
            //new一个新的窗体//
            this.BackColor = Color.Blue;
            //新的窗体背景颜色为蓝色//
            f1.Show();
            //窗体进行显示//
        }
        if (this.Left +this.Width >=Screen.PrimaryScreen.Bounds .Width ||Left <= 0)
        //如果满足他左边到主屏幕的距离加上他自生的宽度大于等于屏幕的宽度或者他的宽度小于等于主屏幕的宽度时//
        {
            x = -x;
            //x等于负x//
        }
       
    }
}

}
难点;
学会并理解定义和使用变量

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值