打开主线程上的新形式 [英] Open a new form on the main thread
本文介绍了打开主线程上的新形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在C#中打开一个新的形式从主线程
How can I open a new form from the main thread in C#?
在这个时刻我使用这个打开它们
At this moment I open them by using this:
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(oppenMainForm));
t.SetApartmentState(ApartmentState.STA);
t.Start();
但是,这将创建一个新的线程...我的主要形式是我的登录表单。而我想即关闭,然后打开我的第二个形式。
But this creates a new thread... My main form is my login form.. And I want that to close and then open my second form.
推荐答案
转到您的Program.cs文件,并修改它,这样你显示你登录表单,然后,它已被关闭后,确定是否应该打开的另一种形式:
Go to your program.cs file and alter it so that you show your login form and then, after it has been closed, determine if you should open up another form:
这很可能会看起来或多或少是这样的:
It'll likely look something more or less like this:
LoginForm loginform = new LoginForm();
Application.Run(loginform);
if (loginform.DialogResult == DialogResult.Yes)
Application.Run(new MainForm());
//TODO handle error cases
这篇关于打开主线程上的新形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文