Winforms 动画GIF输入,请稍候

Winforms 动画GIF输入,请稍候,winforms,animation,Winforms,Animation,我在windows应用程序中有一个请等待表单,它在长时间运行的任务之前被渲染,请等待包含一个动画gif,在这个过程中需要“旋转”,但我无法得到这个工作 我最终使用以下代码获得了正确显示的表单: frmChooser chooser = frmChooser.Instance; chooser.Url = this.UrlTextBox.Text; frmBuildNotification fb = new frmBuildNotification(); fb.Sh

我在windows应用程序中有一个请等待表单,它在长时间运行的任务之前被渲染,请等待包含一个动画gif,在这个过程中需要“旋转”,但我无法得到这个工作

我最终使用以下代码获得了正确显示的表单:

frmChooser chooser = frmChooser.Instance;
chooser.Url = this.UrlTextBox.Text;                
frmBuildNotification fb = new frmBuildNotification();
fb.Show(this);
fb.Update();
Application.DoEvents();
chooser.BuildTreeView();
fb.Close();
this.Hide();
chooser.Show(this);
GIF包含在
frmBuildNotification


我在某个地方读到,您需要重新绘制表单以使图像具有动画效果,但这似乎有点乏味?

您需要保持DoEvents消息泵运行,如果您将通知表单放到另一个线程上,这也会有所帮助。试试这个:

        bool done = false;
        frmBuildNotification fb = null;
        ThreadPool.QueueUserWorkItem((x) =>
        {
            using (fb = new frmBuildNotification())
            {
                fb.Show();
                while (!done)
                    Application.DoEvents();
                fb.Close();
            }
        });
        frmChooser chooser = frmChooser.Instance;
        chooser.Url = this.UrlTextBox.Text;
        chooser.BuildTreeView();
        done = true;
        this.Hide();
        chooser.Show(this); 

线程一次只能做一件事。它不能构建树视图,也不能保持gif动画。使用BackgroundWorker准备数据。或者使用闪屏。