桌面浮動(dòng)窗口(類似惡意廣告)的實(shí)現(xiàn)詳解
更新時(shí)間:2013年06月08日 15:06:38 作者:
本篇文章是對(duì)桌面浮動(dòng)窗口的實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
突然想起來(lái)flash有碰撞反彈飄動(dòng)as控制的效果,所以想起來(lái)用c#也來(lái)做一個(gè)桌面飄動(dòng)碰撞反彈無(wú)標(biāo)題欄窗體。有點(diǎn)像中了惡意病毒廣告效果。
主要代碼如下(使用了一timer控件和一Button(為了我自己控制),窗體的BorderStyle設(shè)置為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;//為了我可以控制停止所以添加的飄與停的切換開關(guān)
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 = "飄動(dòng)";
}
else
{
canMove = true;
//button1.Text = "停止";
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_DoubleClick(object sender, EventArgs e)
{
Application.Exit();
}
暫寫這么多,有時(shí)間把它再增強(qiáng)下更像惡意廣告。~
主要代碼如下(使用了一timer控件和一Button(為了我自己控制),窗體的BorderStyle設(shè)置為None):
復(fù)制代碼 代碼如下:
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;//為了我可以控制停止所以添加的飄與停的切換開關(guān)
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 = "飄動(dòng)";
}
else
{
canMove = true;
//button1.Text = "停止";
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_DoubleClick(object sender, EventArgs e)
{
Application.Exit();
}
暫寫這么多,有時(shí)間把它再增強(qiáng)下更像惡意廣告。~
相關(guān)文章
C#實(shí)現(xiàn)Word和ODT文檔相互轉(zhuǎn)換詳解
ODT文檔格式一種開放文檔格式(OpenDocument Text)。本文以C#及VB.NET代碼展示ODT和Word文檔之間相互轉(zhuǎn)換的方法,感興趣的可以學(xué)習(xí)一下2022-05-05
C#中Json字符串的各種應(yīng)用類實(shí)例講解
這篇文章主要介紹了C#中Json字符串的各種應(yīng)用類實(shí)例講解的相關(guān)資料,需要的朋友可以參考下2015-10-10
c# 解決IIS寫Excel的權(quán)限問(wèn)題
使用以上方法必須對(duì)dcom進(jìn)行配置,給用戶使用office的權(quán)限2012-10-10
C#對(duì)象為Null模式(Null Object Pattern)實(shí)例教程
這篇文章主要介紹了C#對(duì)象為Null模式(Null Object Pattern),以一個(gè)簡(jiǎn)單實(shí)例深入分析了C#為Null情況下的處理方法,需要的朋友可以參考下2014-09-09
C#使用DllImport調(diào)用非托管的代碼的方法
C#調(diào)用非托管代碼的方式主要有Com調(diào)用、DllImport方式調(diào)用、加載非托管動(dòng)態(tài)鏈接庫(kù)、直接執(zhí)行機(jī)器碼等方式?,F(xiàn)在介紹一下我自己常用的DllImport方式調(diào)用MSDN中提到的GetShortPathName方法;2013-03-03

