我用C#开发了一个简单的窗口应用程序(MDI),它可以将数据从SQL导出到Excel。
我正在使用ClosedXML成功地实现这一点。
在执行该过程时,我希望显示一个包含GIF动画图像的picturebox。
我是一个初学者,不知道如何实现这一点,在这个过程完成后,出现了picturebox。
我看到很多帖子说使用后台工作者或线程,我从来没有使用过,发现它很难实现。
我可以有一步一步的例子和解释。
我创建的两个函数,我在执行代码之前和之后调用它们。
private void Loading_On()
{
Cursor.Current = Cursors.WaitCursor;
pictureBox2.Visible = true;
groupBox1.Enabled = false;
groupBox5.Enabled = false;
groupBox6.Enabled = false;
Cursor.Current = Cursors.Arrow;
}
private void Loading_Off()
{
Cursor.Current = Cursors.Arrow;
pictureBox2.Visible = false;
groupBox1.Enabled = true;
groupBox5.Enabled = true;
groupBox6.Enabled = true;
Cursor.Current = Cursors.WaitCursor;
}发布于 2015-08-13 02:10:24
实现这一点的最好方法是在异步任务中运行动画,但相应地,在windows窗体上使用线程睡眠来执行此操作也存在一些限制。
例如:在你的构造函数中,
public partial class MainMenu : Form
{
private SplashScreen splash = new SplashScreen();
public MainMenu ()
{
InitializeComponent();
Task.Factory.StartNew(() => {
splash.ShowDialog();
});
Thread.Sleep(2000);
}在启动了一个新的线程之后,把线程睡眠放在后面是非常重要的,例如,不要忘记你在这个线程上所做的每一个动作都需要调用
void CloseSplash(EventArgs e)
{
Invoke(new MethodInvoker(() =>
{
splash.Close();
}));
}现在你的gif应该可以工作了!
https://stackoverflow.com/questions/31338288
复制相似问题