A touch to C # is attracted by its charm, VB as fast development, C + + the same indirect grammar, is perfect unity. hehe.
So, write a small program, you can fly on the desktop, if this program to do with VB6, it will be very troublesome, and need to call to the API function. But using VS, just need to move the mouse, change the property can be, simply too convenient!
First of all, prepare the bird material, best gif animation, save code to achieve animation (but can not control the speed of animation).
Then there is the add control, 2 Timer to control the direction and animation, a ContextMenu to implement the right menu. (You can, of course, write code without adding it, but that doesn't reflect the fast-developing feature.) Although the IDE's own generated code is very long-winded
Here are three more important features:
1. Form's topmost realizes the animation the most front end display
2. Form's Transparent properties (TransparencyKey) to achieve a non-rectangular appearance
3. The background picture (BackgroundImage) property of the form to show the bird
In the implementation of the method to pay attention to two points:
1. Birds fly to the edge of the steering
2. Mouse move no border form
OK, let's look at the implementation of the specific code:
Achieve Flight steering
private void Timmove_tick (object sender, System.EventArgs e)
{
if (this. left<=0)
{
this.movetoleft=false;
this. BACKGROUNDIMAGE=THIS.IMAGELIST1.IMAGES[4];
this. movex=5;
}
if (this. Left>=system.windows.forms.screen.primaryscreen.workingarea.width-this.width)
{
This.movetoleft=true;
This. Backgroundimage=this.imagelist1.images[0];
This. movex=-5;
}
if (this. top<=0)
{
This. movey=5;
}
if (this. Top>=system.windows.forms.screen.primaryscreen.workingarea.height-this.height)
{
This. movey=-5;
}
This. Left+=movex;
This. Top+=movey;
}
Implementing a mouse move without a border form
private void Form1_mousedown (object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.button==mousebuttons.left)
{
Canmove=true;
curx=e.x;
Cury=e.y;
}
}
private void Form1_mouseup (object sender, System.Windows.Forms.MouseEventArgs e)
{
Canmove=false;
}
private void Form1_mousemove (object sender, System.Windows.Forms.MouseEventArgs e)
{
if (Canmove)
{
This. left = this. Left + E.x-curx;
This. top = this. Top + E.y-cury;
}
}