zoukankan
html css js c++ java
Splash Form
对于需要加载很多组件的应用程序来说,在启动的时候会非常的缓慢,可能会让用户误以为程序已经死掉,这显然不是我们希望看到的。如果能够在启动的时候动态的给用户一些反馈信息(比如当前正在加载的项),那么就可以有效的避免这一问题,并且可以给我们的应用程序增色不少。下边的图片是此代码的效果图。
下面是部分代码:
AppStart 类,包含Main方法
public
class
AppStart
{
public
AppStart()
{
}
[STAThread]
static
void
Main(
string
[] args)
{
//
显示Splash窗体
Splash.Show();
DoStartup(args);
//
关闭Splash窗体
Splash.Close();
}
static
void
DoStartup(
string
[] args)
{
//
做需要的事情
frmMain f
=
new
frmMain();
Application.Run(f);
}
}
Splash功能类:
public
class
Splash
{
static
frmSplash MySplashForm
=
null
;
static
Thread MySplashThread
=
null
;
static
void
ShowThread()
{
MySplashForm
=
new
frmSplash();
Application.Run(MySplashForm);
}
static
public
void
Show()
{
if
(MySplashThread
!=
null
)
return
;
MySplashThread
=
new
Thread(
new
ThreadStart(Splash.ShowThread));
MySplashThread.IsBackground
=
true
;
MySplashThread.ApartmentState
=
ApartmentState.STA;
MySplashThread.Start();
}
static
public
void
Close()
{
if
(MySplashThread
==
null
)
return
;
if
(MySplashForm
==
null
)
return
;
try
{
MySplashForm.Invoke(
new
MethodInvoker(MySplashForm.Close));
}
catch
(Exception)
{
}
MySplashThread
=
null
;
MySplashForm
=
null
;
}
static
public
string
Status
{
set
{
if
(MySplashForm
==
null
)
{
return
;
}
MySplashForm.StatusInfo
=
value;
}
get
{
if
(MySplashForm
==
null
)
{
throw
new
InvalidOperationException(
"
Splash Form not on screen
"
);
}
return
MySplashForm.StatusInfo;
}
}
}
Splash 界面类:
public
class
frmSplash : System.Windows.Forms.Form
{
private
string
_StatusInfo
=
""
;
public
frmSplash()
{
InitializeComponent();
}
private
void
InitializeComponent()
{
//
this
.pictureBox1.Image
=
((System.Drawing.Image)(resources.GetObject(
"
pictureBox1.Image
"
)));
//
}
public
string
StatusInfo
{
set
{
_StatusInfo
=
value;
ChangeStatusText();
}
get
{
return
_StatusInfo;
}
}
public
void
ChangeStatusText()
{
try
{
if
(
this
.InvokeRequired)
{
this
.Invoke(
new
MethodInvoker(
this
.ChangeStatusText));
return
;
}
labStatus.Text
=
_StatusInfo;
}
catch
(Exception e)
{
//
异常处理
}
}
}
主界面类:
public
class
frmMain : System.Windows.Forms.Form
{
public
frmMain()
{
InitializeComponent();
Splash.Status
=
"
状态:载入初始化模块
"
;
System.Threading.Thread.Sleep(
1000
);
Splash.Status
=
"
状态:载入管理模块
"
;
System.Threading.Thread.Sleep(
1000
);
Splash.Status
=
"
状态:载入打印模块
"
;
System.Threading.Thread.Sleep(
1000
);
Splash.Status
=
"
状态:载入插件模块
"
;
System.Threading.Thread.Sleep(
1000
);
Splash.Status
=
"
状态:连接数据库
"
;
System.Threading.Thread.Sleep(
1000
);
Splash.Close();
}
}
查看全文
相关阅读:
HTML5 Video/Audio播放本地文件
jquery 美化弹出提示 漂亮的Dialog 对话框
JavaScript中变量、作用域、内存问题
利用nethogs查看哪些进程占用网络带宽
Dell服务器硬件监控,使用omreport出现object not found 错误解决
filebeat收集nginx的json格式日志
利用logrotate切割nginx的access.log日志
Linux下单机部署ELK日志收集、分析环境
linux开启Rsyslog服务收集日志
mysql占用磁盘IO过高的解决办法
原文地址:https://www.cnblogs.com/hcfalan/p/502730.html
最新文章
UITableView-hightForRow调用时刻-Cell行高计算和缓存Cell行高
iOS-懒加载子控制器的View
ViewWithTag-查找子控件报错
vue页面首次加载缓慢原因及解决方案
linux安装Nginx
前后端对称加密(AES)
egg 框架自动创建数据库表结构
vue之页面缓存问题(基于2.0)
(Git) 优秀Java,Vue项目推荐
(JavaScript) JS方式调用POS机蓝牙打印
热门文章
(JavaScript) 字符串转16进制
支付宝代签约当面付支付
小微商户申请入驻
jquery.autocomplete修改 实现键盘上下键 自动填充
基于jquery扩展漂亮的CheckBox
CSS3属性选择器
jquery放大镜非常漂亮噢
xml获取配置DataTable
Web开发者不可不知的15条编码原则
jQuery总结
Copyright © 2011-2022 走看看