c#--the bird that has been flying

Source: Internet
Author: User

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;
}
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.