突然想起来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();
}
暂写这么多,有时间把它再增强下更像恶意广告。~
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
C#实现猜数字游戏
本文实例为大家分享了c#实现猜数字游戏具体代码,供大家参考,具体内容如下给定一个0-100的随机数字猜其大小题目样式:电脑产生一个0到100之间的随机数字,并且...
[阅读全文]
-
-
C# 可空类型的具体使用
在项目中我们经常会遇到可为空类型,那么到底什么是可为空类型呢?下面我们将从4个方面为大家剖析。1、可空类型基础知识顾名思义,可空类型指的就是某个对象类型可以为空...
[阅读全文]
-
-
-
C#实现猜数字小游戏
本文实例为大家分享了c#实现猜数字小游戏的具体代码,供大家参考,具体内容如下效果如图:代码:using system;using system.collecti...
[阅读全文]
-
-
C#实现简单俄罗斯方块
最近在看《.net游戏编程入门经典 c#篇》 第一章介绍了如何制作俄罗斯方块,自己试了试按照书上的步骤,可算是完成了。于是写下这篇文章留作纪念。1.类的设计在充...
[阅读全文]
-
网友评论