C# 窗口实现Win7简单屏幕泡泡保护程序 和实现聊天窗口震动

首先看一下运行之后的效果图
这里写图片描述
接下来就是代码了

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace FromPaoPao
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            GraphicsPath g = new GraphicsPath();
            g.AddEllipse(0,0,this.Width,this.Height);
            this.Region = new Region(g);
            this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height);
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            if (this.Top > 0 && this.Left > 0 && this.Left >= Screen.PrimaryScreen.WorkingArea.Width - this.Width)
            {
                this.Top -= 3;
            }
            else if (this.Left >0 && this.Top<=0)
            {
                this.Left -= 3;

            }
            else if (this.Bottom <= Screen.PrimaryScreen.WorkingArea.Height)
            {
                this.Top += 3;

            }
            else if (this.Right <= Screen.PrimaryScreen.WorkingArea.Width )
            {
                this.Left+=3;

            }


        }

        private void timer2_Tick(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}

原理就是通过判断屏幕的距离来改变泡泡的方向!布局比较简单,就是在窗口上面放置一个震动的按钮

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Drawing.Drawing2D;

namespace FromPaoPao
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
           /* GraphicsPath g = new GraphicsPath();
            g.AddEllipse(0, 0, this.Width, this.Height);
            this.Region = new Region(g);*/
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int x = this.Location.X;
            int y = this.Location.Y;
            for(int i=0;i<=10;i++)
            {
                this.Location = new Point(x-100,y);
                this.BackColor = Color.AntiqueWhite;
                Thread.Sleep(60);
                this.Location = new Point(x-100,y+100);
                this.BackColor = Color.Aqua;
                Thread.Sleep(60);
                this.Location = new Point(x, y + 100);
                this.BackColor = Color.Azure;
                Thread.Sleep(60);
                this.Location = new Point(x + 100, y + 100);
                this.BackColor = Color.BlanchedAlmond;
                Thread.Sleep(60);
                this.Location = new Point(x + 100, y);
                this.BackColor = Color.Crimson;
                Thread.Sleep(60);
                this.Location = new Point(x + 100, y - 100);
                this.BackColor = Color.DarkCyan;
                Thread.Sleep(60);
                this.Location = new Point(x, y - 100);
                this.BackColor = Color.DarkTurquoise;
                Thread.Sleep(60);
                this.Location = new Point(x - 100, y - 100);
                this.BackColor = Color.Red;
                Thread.Sleep(60);


            }
            MessageBox.Show("你知道震动了多少圈吗?猜出有奖","看一看");

            this.Location = new Point(x, y);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值