惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
美团技术团队
博客园_首页
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
B
Blog
D
DataBreaches.Net
腾讯CDC
C
Check Point Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
U
Unit 42
月光博客
月光博客
V
V2EX
Vercel News
Vercel News
T
The Blog of Author Tim Ferriss
The Cloudflare Blog
博客园 - 叶小钗
Y
Y Combinator Blog

博客园 - 萧萧空间

Windows 2003,XP安装Windows Phone 7 从海量数据中找出中位数(转) 界面开发(五)--- 界面优化 界面开发(四)--- 还窗体的新面貌 界面开发(三)--- 设置窗体的Region 界面开发(二)--- NativeWindow 界面开发(一)--- Hook所有的窗体 界面开发概述 ExtJs扩展之GroupPropertyGrid ExtJs之带图片的下拉列表框 寻找第K大的数的方法总结 我自己的ColorSpy Office 2010 beta版安装 Java反编译工具JD ExtJs Grid Drag Drap 异步窗体实现操作进度(ProgressWindow) 线程封装组件(BackgroundWorker)和线程(Thread) 多线程开发 NSIS 的使用心得
Splash窗体(ProgressWindowForm修改)
萧萧空间 · 2009-11-30 · via 博客园 - 萧萧空间

     上篇中写了一个ProgressWindowForm窗体,主要使用线程来处理系统中执行的大数据量操作的一个多线程解决方案,本次将其修改一下,使用线程去处理系统加载过程中的一些处理事项。

     界面图如下:

     

     这个Splash和原来的ProgressWindowForm的方式一样,只是修改了其中的少许代码,首先 就是本窗体没有了以前的取消方法,删除取消的相关代码就可以了,第二就是窗体不能被强制关闭,也就是说不能使用Alt+F4关闭本窗体,这是很简单的,我在窗体中添加了ProcessDialogKey来去除Alt+F4功能,代码如下:

 1         protected override bool ProcessDialogKey(Keys keyData)
 2         {
 3             switch (keyData)
 4             {
 5                 case Keys.Alt | Keys.F4:
 6                     return true;
 7                 default
 8                     break;
 9             }
10             return base.ProcessDialogKey(keyData);
11         }

   使用Splish的方法就和原来ProgressWindowForm的方法是一样的,主要就是在主窗体显示前,添加如下的代码:

this.Hide();
SplashWindowForm splashWindowForm 
= new SplashWindowForm();
splashWindowForm.Text 
= "测试工作";
System.Threading.ThreadPool.QueueUserWorkItem(
new System.Threading.WaitCallback(SplashDoWork), splashWindowForm);
splashWindowForm.ShowDialog(); 

     SplashDoWork的代码如下:

        private void SplashDoWork(object status)
        {
            SplashWindowForm splashWindowForm 
= status as SplashWindowForm;
            
try
            {
                splashWindowForm.BeginThread(
0300);
                
for (int i = 0; i < 100++i)
                {
                    splashWindowForm.SetDisplayText(
"加载启动项1.");
                    splashWindowForm.StepTo(i);
                    
if (splashWindowForm.IsAborting)
                    {
                        
return;
                    }
                    System.Threading.Thread.Sleep(
100);
                    
if (splashWindowForm.IsAborting)
                    {
                        
return;
                    }
                }
for (int i = 100; i < 200++i)
                {
                    splashWindowForm.SetDisplayText(
"加载启动项2.");
                    splashWindowForm.StepTo(i);
                    
if (splashWindowForm.IsAborting)
                    {
                        
return;
                    }
                    System.Threading.Thread.Sleep(
100);
                    
if (splashWindowForm.IsAborting)
                    {
                        
return;
                    }
                }
for (int i = 200; i < 300++i)
                {
                    splashWindowForm.SetDisplayText(
"加载启动项3.");
                    splashWindowForm.StepTo(i);
                    
if (splashWindowForm.IsAborting)
                    {
                        
return;
                    }
                    System.Threading.Thread.Sleep(
100);
                    
if (splashWindowForm.IsAborting)
                    {
                        
return;
                    }
                }
            }
            
catch (Exception exception)
            {
               MessageBox.Show(exception.Message 
+ Environment.NewLine + exception.StackTrace);
            }
            
finally
            {
                
if (splashWindowForm != null)
                {
                    splashWindowForm.End();
                }
            }
        }

   代码下载:/Files/zhjp11/ProgressWindowWithSplash.rar