【发布时间】:2021-09-08 15:20:20
【问题描述】:
我在 Visual Studio 的应用程序中有 2 个 winform。第一个是加载屏幕,确保没有连接问题,然后打开第二个 winforms,这将是一个登录表单。我使用这种方法关闭第一个表单并打开第二个:
this.Close();
th = new Thread(opennewform); // [opennewform thread: Application.Run(new Login());]
th.SetApartmentState(ApartmentState.STA);
th.Start();
它工作正常,但是当第二个表单打开时它失去焦点。我尝试将this.Activate、this.BringtoFront、this.Show 添加到第二种形式,但它不起作用。我需要的是在第一个表单关闭并打开第二个表单之后,第二个表单是“活动”表单,所以它总是会弹出。我还需要使用 close/thread 方法,以便第一个表单真正关闭,而不仅仅是this.hide();,而是实际上留在后台。提前感谢您的帮助。
【问题讨论】:
-
查看this问题的答案,了解如何正确运行启动画面。
标签: c# visual-studio winforms focus