GIF animation does not work on Windows Form

I have 2 WinForms

Form2 uses Infragistics ultraTabControl. On the Modify tab, im Form Display 1.

In Form1

I have a PictureBox assigned with an animated GIF

In shape2

I am showing Form1 as follows.

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

Problem

GIF does not play animation.

+5
source share
7 answers

solvable

My current thread is busy playing GIF animations.

I tried as many ways as Application.DoEvents (); etc. But nothing helped me.

The answer in the next question that Threading uses is a very good working idea.

fooobar.com/questions/167272 / ...

Thanks for everyone.

+1
source

Make sure that you have an image in the image property. NO IMAGE PROPERTY BACKGROUND. This is the mistake I made

+7
source

It works great for me. I just dragged a new pictureBox over the form and set the image property to the Form_Load () event and showed the GIF animation.

I did the same as you by clicking the button:

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

In my test form:

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

Note. If your image window is disabled, it will not animate Gif

Reference:
How do you show animated GIFs in Windows form (C #)
Animated progress bar in C # (Windows Forms)

Try to implement this link: Animated GIF in the picture will not animate .

+4
source

The best way to achieve this is to run the animation in the async task, but, accordingly, some restrictions can be made in the form of a window using:

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

My popup is displayed using gif (loading)

For example: in your constructor

 public partial class MainMenu : Form { private SplashScreen splash = new SplashScreen(); public MainMenu () { InitializeComponent(); Task.Factory.StartNew(() => { splash.ShowDialog(); }); Thread.Sleep(2000); } 

Be sure to put Thread.Sleep(int) after starting a new one, do not forget that every action you did in this thread should be called, for example:

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

Now your gif should work!

+1
source

This question has already been raised before. Although the approach is different, the concept of the questions is the same.

fooobar.com/questions/49883 / ...

Source project where you can use Code Project

I think this will help you.

0
source

If none of the previous answers work for you, another idea is to update the image tag or write it on the fly using jQuery.
In my case, I needed to show an animated GIF when the button on the form was clicked. Previously, he appeared, but did not animate. I just added a jQuery event when a button was pressed that added an image tag on the fly to the div via the parent html () tag function.

 $('.showhidegif').html("<img src='/Content/img/angled-spinner.gif' />"); <div class="col-sm-12 showhidegif"></div> 

It is worth noting if you are already using jquery on your page.

0
source

I had the same problem, and I came across different solutions, doing what I used to solve several different problems. And finally, below is that I put several parts from different posts together that worked for me as expected.

  private void btnCompare_Click(object sender, EventArgs e) { ThreadStart threadStart = new ThreadStart(Execution); Thread thread = new Thread(threadStart); thread.SetApartmentState(ApartmentState.STA); thread.Start(); } 

Here is the Run method, which also calls the PictureBox control:

  private void Execution() { btnCompare.Invoke((MethodInvoker)delegate { pictureBox1.Visible = true; }); Application.DoEvents(); // Your main code comes here . . . btnCompare.Invoke((MethodInvoker)delegate { pictureBox1.Visible = false; }); } 

Keep in mind that the PictureBox is invisible from the properties window or below:

 private void ComparerForm_Load(object sender, EventArgs e) { pictureBox1.Visible = false; } 
0
source

Source: https://habr.com/ru/post/1403858/


All Articles