如图需要执行某个方法弹出等待窗口,方法执行完成后窗体自动关闭
public Thread Loading(LoadingForm f)
{
System.Threading.Thread th;
th = new Thread(new ThreadStart(delegate ()
{
f.ShowDialog();
}));
th.Start();
return th;
}
设计一个弹出窗体,放一个pictureBox将Image属性放一个gif图片,然后将窗体设置透明,
public partial class LoadingForm : Form
{
public LoadingForm()
{
InitializeComponent();
this.BackColor = Color.White; this.TransparencyKey = Color.White;//设置窗体透明
}
}
在线程中定义和打开等待窗口,把线程作为参数传入方法中,在方法执行完毕后使用线程的销毁操作实现等待窗口的关闭。
调用方法
LoadingForm f = new LoadingForm();//
Thread th = Loading(f);
Methods();//要执行的方法
f.Close();
th.Abort();