桌面浮動窗口(類似惡意廣告)的實現(xiàn)詳解
更新時間:2013年06月08日 15:06:38 作者:
本篇文章是對桌面浮動窗口的實現(xiàn)方法進行了詳細的分析介紹,需要的朋友參考下
突然想起來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();
}
暫寫這么多,有時間把它再增強下更像惡意廣告。~
主要代碼如下(使用了一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();
}
暫寫這么多,有時間把它再增強下更像惡意廣告。~
相關文章
AjaxControlToolkit AjaxFileUpload 顯示英文改成中文的解決方法
AjaxControlToolkit AjaxFileUpload 顯示英文改成中文的解決方法,需要的朋友可以參考一下2013-03-03解析如何正確使用SqlConnection的實現(xiàn)方法
本篇文章對如何正確使用SqlConnection的實現(xiàn)方法進行了詳細的分析介紹,需要的朋友參考下2013-05-05Unity UGUI的ContentSizeFitter內容尺寸適應器組件使用示例
這篇文章主要為大家介紹了Unity UGUI的ContentSizeFitter內容尺寸適應器組件使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08