Solved

run animated gif on onclick

Posted on 2004-09-15
6
1,053 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

929 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now