我有一个winforms应用程序,我在其中使用2个表单来显示所有必要的控件.第一个表单是一个启动画面,它告诉用户它正在加载等等.所以我使用以下代码:
Application.Run( new SplashForm() );
Run Code Online (Sandbox Code Playgroud)
一旦应用程序完成加载,我希望SplashForm隐藏或我发送到后面和主要显示.我目前正在使用以下内容:
private void showMainForm()
{
this.Hide();
this.SendToBack();
// Show the GUI
mainForm.Show();
mainForm.BringToFront();
}
Run Code Online (Sandbox Code Playgroud)
我所看到的是显示了MainForm,但SplashForm仍然可以在"顶部"显示.我目前正在做的是点击MainForm手动将它带到前面.有关为什么会发生这种情况的任何想法?
我有一个WinForm加载方法,需要很长时间来收集一些数据,以显示给用户.
在执行此方法时,我会显示一个带有大字体的表单,并带有"正在加载"字样.
但是,有时会出现此错误,并且"加载"进度表单不会关闭,然后最终我的整个应用程序将退出:
创建窗口句柄时出错.在System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
在我在load方法中执行代码时,是否有更好的方法来显示我的进度/加载表单?
这是我的代码:
//I launch a thread here so that way the Progress_form will display to the user
//while the Load method is still executing code. I can not use .ShowDialog here
//or it will block.
//Progress_form displays the "Loading" form
Thread t = new Thread(new ThreadStart(Progress_form));
t.SetApartmentState(System.Threading.ApartmentState.STA);
t.IsBackground = true;
t.Start();
//This is where all the code is that gets the data from the database. This could
//take upwards of 20+ seconds.
//Now I want …Run Code Online (Sandbox Code Playgroud)