Solved

run animated gif on onclick

Posted on 2004-09-15
6
1,059 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
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

839 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