Desktop floating window of similar to the implementation of malicious advertising
- 2020-05-17 06:11:25
- OfStack
It suddenly occurred to me that flash has the effect of collision bounce flapping as control, so I remembered to use c# to also make a desktop flapping bounce without title bar form. It's kind of like a viral AD.
The main code is as follows (using the 1timer control and 1Button(for my own control), the form's BorderStyle is set to None) :
Write so much that you have time to sharpen it up to look more like a malicious AD. ~
The main code is as follows (using the 1timer control and 1Button(for my own control), the form's BorderStyle is set to 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;// For me to be able to control the stop so add the float and stop toggle switch
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 = " flap ";
}
else
{
canMove = true;
//button1.Text = " stop ";
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_DoubleClick(object sender, EventArgs e)
{
Application.Exit();
}
Write so much that you have time to sharpen it up to look more like a malicious AD. ~