Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIF Animation not working in Windows Form

I have 2 WinForms

Form2 uses Infragistics ultraTabControl. On Tab Changing im Showing Form1.

In Form1

I have a PictureBox assigned with animated GIF

In Form2

I am displaying Form1 like this.

Form1 frmOne=new Form1();
frmOne.Show();

Problem

GIF is not playing animation.

like image 348
aWebdesigner09 Avatar asked Mar 28 '12 10:03

aWebdesigner09


4 Answers

Make sure you have your image in the image property NOT THE BACKGROUND IMAGE PROPERTY. That's the mistake I made

like image 92
Help Avatar answered Oct 24 '22 06:10

Help


It is working fine for me. I have just dragged a new pictureBox on form and setting image property at Form_Load() event and showing GIF animated.

I did same as you on button click:

  TestForms.NavBarTest newForm = new TestForms.NavBarTest();
            newForm.Show();

At my Test Form:

private void NavBarTest_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = NavronChartControl.Properties.Resources.url;
        }

Note: If your picture box is disabled then it will not animate the Gif

Reference:
How do you show animated GIFs on a Windows Form (c#)
Animated Progress Indicator in C# (Windows Forms)

Try to implement using this link:Animated GIF in picturebox won't animate apprach.

like image 42
Niranjan Singh Avatar answered Oct 24 '22 05:10

Niranjan Singh


The best way to achieve it is to run the animation in an async task, but accordingly, some limitations are possible to do that on windows form using:

System.Threading.Thread.Sleep(int milliseconds).

My splash view is displayed with a gif (loading)

e.g.: In your constructor,

public partial class MainMenu : Form
{

    private SplashScreen splash = new SplashScreen();

    public MainMenu ()
    {
        InitializeComponent();

        Task.Factory.StartNew(() => {
            splash.ShowDialog();
        });

       Thread.Sleep(2000);
   }

It is imperative to put the Thread.Sleep(int) after starting a new one, don't forget that every action you did on this thread needs to be invoked, for example:

    void CloseSplash()
    {
        Invoke(new MethodInvoker(() =>
        {
           splash.Close();
        }));
    }

Now your gif should work!

like image 39
erasmosoares Avatar answered Oct 24 '22 06:10

erasmosoares


Solved

My current Thread is busy to Play GIF Animation.

I tried So many ways like Application.DoEvents(); etc. But every thing can't helped me.

The answer in the following Question, which uses Threading is a very great working idea.

StackOverFlow: Show/Hide Splash Screen

Thanks for every one.

like image 1
aWebdesigner09 Avatar answered Oct 24 '22 05:10

aWebdesigner09