当前位置: 移动技术网 > IT编程>开发语言>c# > 桌面浮动窗口(类似恶意广告)的实现详解

桌面浮动窗口(类似恶意广告)的实现详解

2019年07月18日  | 移动技术网IT编程  | 我要评论
突然想起来flash有碰撞反弹飘动as控制的效果,所以想起来用c#也来做一个桌面飘动碰撞反弹无标题栏窗体。有点像中了恶意病毒广告效果。
主要代码如下(使用了一timer控件和一button(为了我自己控制),窗体的borderstyle设置为none):
复制代码 代码如下:

        int screenwidth = systeminformation.primarymonitormaximizedwindowsize.width;
        int screenheight = systeminformation.primarymonitormaximizedwindowsize.height;
        private int speedx = 4;
        private int speedy = 3;
        private bool canmove = true;
        int myswitch = 1;//为了我可以控制停止所以添加的飘与停的切换开关
        private void timer1_tick(object sender, eventargs e)
        {
            if (canmove)
            {
                this.desktoplocation = new point(this.desktoplocation.x + speedx, this.desktoplocation.y + speedy);
                if (this.desktoplocation.x + this.width >= screenwidth || this.desktoplocation.x < 0)
                {
                    speedx = -speedx;
                }
                if (this.desktoplocation.y + this.height >= screenheight || this.desktoplocation.y < 0)
                {
                    speedy = -speedy;
                }
            }
        }
        private void button1_click(object sender, eventargs e)
        {
            myswitch *= -1;
            if (myswitch == -1)
            {
                canmove = false;
                //button1.text = "飘动";
            }
            else
            {
                canmove = true;
                //button1.text = "停止";
            }
        }
        private void form1_load(object sender, eventargs e)
        {
        }
        private void form1_doubleclick(object sender, eventargs e)
        {
            application.exit();
        }

暂写这么多,有时间把它再增强下更像恶意广告。~

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网