?
Solved

Need sample code:  small little animation

Posted on 2003-11-05
13
Medium Priority
?
672 Views
Last Modified: 2013-11-19
I have a process that takes a while (30 seconds - 2 minutes or so) and I would like to do a small little animation just to show that the program hasn't hung during this waiting period.  (the GUI is in a seperate thread, it still can't really do much during this time).  I have a graphic/logo that is symmetric about the x-axis, and I would think it would be good If I could make it appear to be rotating about the y-axis.  But, I am open to any suggestions.  I don't really want to spend a lot of time learning GDI+ or anything, so if you can point me to a good tutorial or something, I would appreciate it.  
0
Comment
Question by:jjacksn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +1
13 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9688111
A very simple solution: put a picture box on your form. Create a number of files called pic01.bmp, pic02.bmp, etc. or any other sequence you can follow. You can also use other format supported by .Net picture box. Then implement a change of the picture (in a separate thread) and sleep this thread for a while until you operation finishes.

The following example shows this in case you have a loop from 0 to 19 and you have 4 pictures: pic01.bmp, pic02.bmp, pic03.bmp and pic04.bmp in the current folder. You need to change the name and number of pictures and the loop stopping to be when your process stops. Some thread synchronization needed there....

private void button1_Click(object sender, System.EventArgs e)
{
      new System.Threading.Thread (new System.Threading.ThreadStart (ThreadBody)).Start();
}

private void ThreadBody()
{
      for (int i = 0; i < 20; i++)
      {
            this.pictureBox1.Image = System.Drawing.Image.FromFile ("pic" + ((i % 4).ToString().PadLeft (2, '0')) + ".bmp");
            System.Threading.Thread.Sleep (100);
      }
}
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 2000 total points
ID: 9688124
Another, much simpler solution: create an animated GIF file and put it in the picture box. It works immediately.
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9688138
Of course you will set the GIF image at the operation start and remove it on operation end.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 15

Expert Comment

by:jimmack
ID: 9688146
Well, since no one else has commented, I'll make a suggestion (BTW: I'm *way* out of my topic area here ;-))

Can you create an animated .GIF and put that on a dialog?

All you'll need to do to create it is to take your existing logo and use a graphics package that can save animated gif's, then create each frame by resizing the image horizontally by a couple of pixels at a time.

I suspect purpleblob might have some ideas, but he could be waiting for you to accept or comment on previous questions.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9688156
Hi TheAvenger,

  You couldn't have timed that any better ;-)
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9688178
:-))
0
 
LVL 6

Expert Comment

by:purpleblob
ID: 9690087
jimmack thanks for the thoughts - but I haven't said anything on this as I think TheAvenger has pretty much covered the two best routes to implementing this - one of which you have covered also.

The animated GIF will probably give you the best control for creating your animation - ofcourse you could always look at embedding the Flash OCX and run a Flash animation - just to really "flash" ;-)
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9690651
Ok,

We already have the rotating graphic in flash, how would i embed it?  
0
 
LVL 6

Expert Comment

by:purpleblob
ID: 9690814
Well there's a Flash ActiveX control (which is what you see in IE when embedding Flash in web pages).

It's the Shockwave Flash Object in the COM objects. Add this to your toolbox by selecting a toolbox tab then right mouse clicking and selecting Add/Remove Items... select the COM Components find Shockwave Flash Object and then press OK adding it to your toolbox.

Now you've got it you can place it on a Form and set the Movie property the the path/filename of your .swf file and your on your way, you might need the stop and playing properties to interact with your animation

0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9692535
Is binding your application with Flash really a good solution for such a simple task? Isn't it better to use the processor power for the real thing you are doing behind, not for loading Flash and the movie? Also remember that this way you will bind to Flash, everyone who uses your app will need it installed, and some customers may be somewhat unhappy about that...
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9692977
I'm not going to use flash, I was just wondering for future reference.  the GIF is the way to go.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9692994
I can't believe I missed out on 2000 points by 2 minutes! ...

In a topic I know next to nothing about ;-)  ...

Next time, I won't dither.  I'll just get in there an tell you C# guys what's what ;-)

0
 
LVL 6

Expert Comment

by:purpleblob
ID: 9693181
:-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question