Solved

run animated gif on onclick

Posted on 2004-09-15
6
1,070 Views
Last Modified: 2012-05-05
my animated that shows work being done gif does not show when i click on the button.


CODE:

Ani.Visible = true; 'this is the animated gif

///Do Some Work that should take awhile to complete


Ani.Visible = false;

I've found that if I comment the 'Ani.Visible = false' out the gif would appear.

0
Comment
Question by:vinny45
[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
6 Comments
 
LVL 24

Expert Comment

by:Justin_W
ID: 12071422
Is your "work" code running in a different thread?  If so, you need to wait for the thread to complete before making the GIF invisible again.
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 500 total points
ID: 12071599
CODE:

    System.Threading.Thread workThread = new System.Threading.Thread(new System.Threading.ThreadStart(DoSomeWork));
    workThread.IsBackground = true;
    workThread.Start();

You will need these methods too:

    void ShowAni()
    {
      Ani.Visible = true;
    }

    void HideAni()
    {
      Ani.Visible = false;
    }

    void DoSomeWork()
    {
      Invoke(new System.Threading.ThreadStart(ShowAni));
     
      // Do some work that should take a while to complete
     
      Invoke(new System.Threading.ThreadStart(HideAni));
    }
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12080323
You might be able to use this:

Ani.Visible = true; 'this is the animated gif

Application.DoEvents;

Ani.Visible = false;

Bob
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 10

Expert Comment

by:eternal_21
ID: 12081514
TheLearnedOne, unfortunately that will work as far as displaying the image goes, but GIF animation will not occur.  The form's main thread is busy working, and does not animate the GIF.  The only solution is to move your work into another thread.
0
 

Expert Comment

by:malanois
ID: 12089520
eternal,

I have been working on another thread for the same thing.

how do you go about creating another thread for the gif.

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21133658.html

Try:

showimage

Application.DoEvents <-- add this.

Fill
hideimage

Bob


 
Comment from malanois
Date: 09/16/2004 10:58AM PDT
 Your Comment  


hmmmmm????????

The gif comes up,

however the animation only shows on bar and hangs.???



 
Comment from TheLearnedOne  feedback
Date: 09/16/2004 10:59AM PDT
 Comment  


What happens if you don't do the Fill and don't hide the image?  Does the animation work correctly?

Bob
 
Comment from malanois
Date: 09/16/2004 11:05AM PDT
 Your Comment  


yes it works if i dont hide and unhide


 
Comment from TheLearnedOne  feedback
Date: 09/17/2004 07:01AM PDT
 Comment  


Take a look here:

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21132894.html#12081514

I learned something new, without even having to ask a question :)

Bob
 
Comment from malanois
Date: 09/17/2004 11:53AM PDT
 Your Comment  


that is great

Thank You so Much

:)

MJ
 
Comment from malanois
Date: 09/17/2004 12:43PM PDT
 Your Comment  


Well now you got me thinking,

Im trying to play with this.

Ive searched a couple items about thread and I keep getting errors

 Private thread As System.Threading.Thread

    Public Sub Threading()
        thread = New System.Threading.Thread(showimage)

    End Sub


    Public Sub showimage()
        showbx.Show()
    End Sub
    Public Sub hideimage()
        showbx.Hide()
    End Sub

?????????????????????

MJ
 
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 12092312
malanois, I have converted the code to VB for your convienence:


  Public Sub ShowImage()

    pictureBox.Show()

  End Sub

  Public Sub HideImage()

    pictureBox.Hide()

  End Sub

  Private Sub DoWork()

    ShowImage()

    // Do your work here

    HideImage()

  End Sub

  Private Sub StartDoWork()

    Dim workThread As New System.Threading.Thread(AddressOf DoWork)
    workThread.Start()

  End Sub


Just call StartDoWork() to get the process going!
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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