First create a project in VS, project type Select vc#, create a Windows Forms application such as:
After you click OK, set the form content in the form, and add three timers to the form from the toolbox, such as:
In the form blank, right-click, click View Code, and under the initialization function, add the following code:
The code is as follows:
int screenwidth = SystemInformation.PrimaryMonitorMaximizedWindowSize.Width; Width of the screen
int screenheight=systeminformation.primarymonitormaximizedwindowsize.heigh;//The height of the screen
Double-click Timer1 to add the following code to the event function, such as:
The code is as follows:
Point mypos = new Point (this. Desktoplocation.x, this. DESKTOPLOCATION.Y); The current position of the form
if (mypos.x + Width < screenwidth)
{
This. Desktoplocation = new Point (mypos.x + 1, mypos.y);
}
Else
{
This. Desktoplocation = new Point (0, 0);
}
Double-click "Horizontal flapping" to add the following code to the event function, such as:
The code is as follows:
This.timer1.Enabled = true;
this.timer2.Enabled = false;
this.timer3.Enabled = false;
Similarly double-click "Vertical Flare" to add code:
this.timer1.Enabled = false;
This.timer2.Enabled = true;
this.timer3.Enabled = false;
-
Double-click Timer2, add the following code to the event response function, such as: Code as follows:
point MyPos = New Point (this. Desktoplocation.x, this. DESKTOPLOCATION.Y); //The current position of the form
if (Mypos.y + Height < screenheight)
{
this. Desktoplocation = new Point (mypos.x, Mypos.y + 1);
}
Else
{
this. Desktoplocation = new Point (0, 0);
}
-
Similarly double-click Timer3 and add the following code:
point mypos = new Point ( This. Desktoplocation.x, this. DESKTOPLOCATION.Y); //The current position of the form
if (mypos.x + Width < ScreenWidth | | Mypos.y + Height < screenheight)
{
&N Bsp this. Desktoplocation = new Point (mypos.x + 1, mypos.y + 1);
}
Else
{
this. Desktoplocation = new Point (0, 0);
}
Then double-click the Flare form to add the following code:
this.timer1.Enabled = false;
this.timer2.Enabled = false;
This.timer3.Enabled = true;
Similarly double-click to stop flapping, add the following code:
this.timer1.Enabled = false;
this.timer2.Enabled = false;
this.timer3.Enabled = false;
Finally, double-click on the blank in the form to create the Form1_Load event and add the following code, such as:
The code is as follows: This.timer1.Enabled = true;
Start debugging and run the results such as: