案頭浮動視窗(類似惡意廣告)的實現詳解

來源:互聯網
上載者:User

突然想起來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();
}

暫寫這麼多,有時間把它再增強下更像惡意廣告。~

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.