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();
}
}
查看全文
相关阅读:
ajax_基础1
省市数据库脚本TblArea.
c#中怎么使用dos命
Lambda表达式
面试收录
.Net牛逼程序猿要懂得
Web.config 配置文件
sql 查询所有数据库、表名、表字段总结
Json在net与页面之间的传递
『转』SAP统驭科目解释
原文地址:https://www.cnblogs.com/hcfalan/p/502730.html
最新文章
handler的使用如何实现Android计时与倒计时的几种方法
技巧们
Acitvity的亲和力
如何安全退出已调用多个Activity的Application?
书们
Activity 的四种模式
火狐插件集锦
SVN的405错误
自定的View菜单
android 点亮屏幕与解锁
热门文章
ActivityManager: java.lang.SecurityException 问题
Android 编程设置 APN
[转]从本地电子商务中走出来,6个很好的O2O模式解析
Andrioid 多点触摸的几个方法
不知道是什么
Android 使用 SMTP 发送邮件
获取 Android 设备的唯一标识码
vue中 routerlink 传递参数以及获取
Vue中常见参数传递方式
Win7 IIS配置解决ASP的500错误
Copyright © 2011-2022 走看看