请看下面的代码:
var splashForm = new SplashForm();
m_Thread = new Thread( () => System.Windows.Forms.Application.Run( splashForm ) )
m_Thread.Start();
// Do some initialization
// ...
// the following method just invokes `Close()` on the right thread
splashForm.Shutdown();
// Loop until the thread is no longer alive
// ...
System.Windows.Forms.Application.Run( mainForm );
Run Code Online (Sandbox Code Playgroud)
它看起来好像一切正常:首先我看到了闪屏,后来主变形开始了.但不知怎的,我得到了奇怪的错误,例如:图形元素(无尽的ProgressBar)没有正确显示.
编辑:我有两个进度条,一个在启动画面上,在主窗体上.他们都在无尽模式中表现出相同(错误)的行为:没有进步,只有纯粹的背景./编辑
在我看来,这是由于Application.Run()不同线程的调用.在启动启动画面之前,可以通过调用mainForm的任何函数/属性来消除此错误 - 例如
mainForm.Text = mainForm.Text;
Run Code Online (Sandbox Code Playgroud)
任何人都可以请确认此代码可能会导致问题 - 或者它应该表现良好,我必须在其他地方寻找错误?
我已经看过了flashscreen实现,我知道它可以以不同的方式完成.但我有兴趣了解这个实现及其可能存在的问题.谢谢!
天哪,我找到了答案:
Application.EnableVisualStyles();如果我的 mainForm 在 ctor 中被调用(为什么?)。必须在创建任何控件之前调用它。把它移到 就static Main()成功了。无限 (ProgressBarStyle.Marquee) 进度条需要视觉样式。
现在这个闪屏解决方案可以正常工作了。
| 归档时间: |
|
| 查看次数: |
16863 次 |
| 最近记录: |