Simple Arrow Animation using GDI Plus in C#

No.of Views1513
Bookmarked2 times
Downloads 
Votes0
By  ninethsense   On  16 Feb 2010 00:02:57
Tag : CSharp , Miscellaneous Controls
Simple Arrow Animation using GDI Plus in C#
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

This simple program explains how simple animations are implemented, using for loops etc

Image Loading

More About

Actually, this program was made for my Instant Messaging Client - Gaim. I needed to know when my boss come online and when he went offline. Gaim has a feature called "Buddy Pounce" which allows users to trigger events. As per my logic, when a user logs in, my application will give me a signal by flying an arrow from right-bottom to left-top. And when he goes offline, the arrow moves from left-top to right-bottom.

Using the code

The images are stored as resources, and I call them depending on the value of Status:

this.BackgroundImage = Resource1.arrow2;

I have used this code to check whether the user is logged in or logged off. This accepts command line arguments. When Status is true, it means "LogIn", otherwise it means "LogOff".

if (args.Length > 0)
{
if (args[0].ToString() == "logoff")
{
Status = false;
}
}

The animation logic is placed inside a Timer_Tick method. Inside the method, the screen width and height are validated, so this program will work under all screen resolutions. An Application.DoEvents(); call is placed in between, to avoid system concentrating on this app only.

private void timer1_Tick(object sender, EventArgs e)
{
Application.DoEvents();

if (Program.Status)
{
if (this.Top <= 0 || this.Left <= 0)
{
timer1.Enabled = false;
Application.Exit();

}
this.Left -= 25;
this.Top -= 15;
}
else{
if (this.Top > Screen.GetBounds(this).Height ||
this.Left > Screen.GetBounds(this).Width)
{
timer1.Enabled = false;
Application.Exit();

}
this.Left += 25;
this.Top += 15;
}
}

Conclusion

This is my second version of this program but, this is my first version of this article.

Sample Project Source

Download source files -20 kb

 
Sign Up to vote for this article
 
About Author
 
ninethsense
Occupation-
Company-
Member Type-Junior
Location-Not Provided
Joined date-21 Jul 2009
Home Page-http://blog.ninethsense.com/
Blog Page-http://blog.ninethsense.com/
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top