当前位置: 首页 > 编程语言 > C#

C#winformsSplash(Splash)FormNotHidingShare

时间:2023-04-10 11:39:53 C#

第一个窗体是一个启动画面,告诉用户它正在加载等。所以我使用以下代码:Application.Run(newSplashForm());应用程序完成加载后,我希望SplashForm隐藏或我发送到后面和主要显示。我目前正在使用以下内容:privatevoidshowMainForm(){this.Hide();这个.SendToBack();//显示GUImainForm.Show();mainForm.BringToFront();我所看到的只是显示MainForm,但SplashForm仍然可以显示在“顶部”。我目前正在做的是单击MainForm以手动将其置于最前面。关于为什么会发生这种情况的任何想法?可能您只想关闭启动窗体,而不是将其发回。我在一个单独的线上运行splash表(这是SplashForm类):classSplashForm{//DelegateforcrossthreadcalltocloseprivatedelegatevoidCloseDelegate();//要显示为初始屏幕的表单类型。私有静态SplashFormsplashForm;staticpublicvoidShowSplashScreen(){//确保它只启动一次。如果(splashForm!=null)返回;线程thread=newThread(newThreadStart(SplashForm.ShowForm));thread.IsBackground=true;thread.SetApartmentState(ApartmentState.STA);线程。开始();}staticprivatevoidShowForm(){splashForm=newSplashForm();应用程序运行(splashForm);}staticpublicvoidCloseForm(){splashForm.Invoke(newCloseDelegate(SplashForm.CloseFormInternal));}staticprivatevoidCloseFormInternal(){splashForm.Close();splashForm=null;}...}并主要程序函数如下所示:[STAThread]staticvoidMain(string[]args){SplashForm.ShowSplashScreen();MainFormmainForm=newMainForm();//这需要很长时间SplashForm.CloseF秩序();应用程序运行(主窗体);}这对于防止您的闪屏阻挡您的注意力并将主窗体在关闭后推到后台是必不可少的:protectedoverrideboolShowWithoutActivation{get{returntrue;}}会将此添加到您的初始表单类中如果我理解正确,您应该只在主表单上使用Application.Run。因此,要么首先使用以下方式显示您的启动器:using(MySplashform=newMySplash())form.ShowDialog();然后随时在MySplash中手动关闭它。或者在带有加载事件处理程序的主窗体中显示它,然后等待它关闭或其他任何操作,直到您让Load方法完成。(可能在显示之前将Visible设置为false然后返回true。我相信这可能是我当前设计中的一个设计缺陷!我认为实现我需要的最好方法是让MainForm可以控制一切......所以我可以使用:Application.Run(newMainForm());然后这将负责显示/更新/隐藏SplashScreen。这样我就可以对MainForm管理的系统的其余部分进行必要的复杂操作。上面是C#学习教程:C#winforms启动(Splash)窗体不隐藏所有分享的内容,如果对大家有用,需要详细了解C#学习教程,希望大家多多关注这篇文章整理自网络,不代表立场,如涉及侵权,请点击右边联系管理员删除,如需转载请注明出处: