好吧,我有这个类显示一个“正在加载...”初始屏幕。当我在Initialize()上调用它时效果很好,但在Form_Load上不会。而不是在Form_Load的开始处显示,它显示在所有表格被填充后,然后挂在那里(没有锁定)。C#Winforms - 飞溅屏幕挂在Form_Load
class innerLoad
{
//Delegate for cross thread call to close
private delegate void CloseDelegate();
//The type of form to be displayed as the splash screen.
private static frmLoading splashForm;
static public void ShowSplashScreen()
{
// Make sure it is only launched once.
if (splashForm != null)
return;
Thread thread = new Thread(new ThreadStart(innerLoad.ShowForm));
thread.IsBackground = true;
//Thread.Sleep(100);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
//volatile static public bool isOpen = false;
static private void ShowForm()
{
splashForm = new frmLoading();
splashForm.ShowDialog();
splashForm.Dispose();
}
static public void CloseForm()
{
try
{
if (splashForm == null)
return;
splashForm.Invoke(new CloseDelegate(innerLoad.CloseFormInternal));
}
catch
{
}
}
static private void CloseFormInternal()
{
splashForm.Close();
splashForm = null;
}
}
这里是在Form_Load代码:
private void frmPayGen_Load(object sender, EventArgs e)
{
//th1 = new Thread(LoadingForm);
//th1.Start();
//Thread.Sleep(500);
innerLoad.ShowSplashScreen();
fill();
innerLoad.CloseForm();
//Thread.Sleep(500);
}
我感谢您的帮助,我喜欢这个网站...帮助我很多:d
[VS2010在64位版本的Windows上的WinForms应用程序中未显示未处理的异常消息](http://stackoverflow.com/questions/4933958/vs2010-does-not-show-unhandled-异常消息在winforms应用程序上) –