SplashScreen,就是平时我们说的溅射屏幕,任何一个做过客户端程序的coder应该对它都不陌生,因为它能提升用户体验,让软件看上去更美。SplashScreenForm通常进入程序时是打开,主窗体加载完毕后退出。一般来说,SplashScreenForm比较简洁,窗体的内容只是显示程序主题、版权等信息;复杂些的,可以显示主程序的加载项目情况。

  下面是我实现的一个SplashScreen类:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Reflection; namespace SplashScreen
{
public class SplashScreen
{
private static object _obj = new object(); private static Form _SplashForm = null; private static Thread _SplashThread = null; private delegate void ChangeFormTextdelegate(string s); public static void Show(Type splashFormType)
{
if (_SplashThread != null)
return;
if (splashFormType == null)
{
throw (new Exception());
} _SplashThread = new Thread(new ThreadStart(delegate()
{
CreateInstance(splashFormType);
Application.Run(_SplashForm);
})); _SplashThread.IsBackground = true;
_SplashThread.SetApartmentState(ApartmentState.STA);
_SplashThread.Start();
} public static void ChangeTitle(string status)
{
ChangeFormTextdelegate de = new ChangeFormTextdelegate(ChangeText);
_SplashForm.Invoke(de, status);
} public static void Close()
{
if (_SplashThread == null || _SplashForm == null) return; try
{
_SplashForm.Invoke(new MethodInvoker(_SplashForm.Close));
}
catch (Exception)
{
}
_SplashThread = null;
_SplashForm = null;
} private static void ChangeText(string title)
{
_SplashForm.Text = title.ToString();
} private static void CreateInstance(Type FormType)
{
if (_SplashForm == null)
{
lock (_obj)
{
object obj = FormType.InvokeMember(null,
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);
_SplashForm = obj as Form;
_SplashForm.TopMost = true;
_SplashForm.ShowInTaskbar = false;
_SplashForm.BringToFront();
_SplashForm.StartPosition = FormStartPosition.CenterScreen;
if (_SplashForm == null)
{
throw (new Exception());
}
}
}
}
}
}

调用的时候只需要传入你需要作为溅射屏幕的窗体,然后在主窗体加载完毕后调用close方法:

namespace SplashScreen
{
public partial class MainForm : Form
{
public MainForm()
{
SplashScreen.Show(typeof(SplashForm));
InitializeComponent();
Thread.Sleep();
SplashScreen.ChangeTitle("");
Thread.Sleep();
SplashScreen.ChangeTitle("");
Thread.Sleep();
SplashScreen.ChangeTitle("");
Thread.Sleep();
SplashScreen.ChangeTitle("");
SplashScreen.Close();
}
}
}

我也来SplashScreen的更多相关文章

  1. Day 2:增加SplashScreen

    If you want to add just single image, then create a pic in the size of 480*800 and name it as Splash ...

  2. 设置 phoneGap/Cordova 3.4 应用程序启动动画闪屏 SplashScreen

    当Cordova 程序打包并安装到手机中后,我们会发现启动程序时,会有数秒的黑屏现象,常见的解决方法则是设置闪屏后面. 这里以 Android 程序为例,介绍Cordova设置启动画面的方法. 1. ...

  3. Unity-WIKI 之 SplashScreen

    组件功能 在屏幕上的一个启动画面消失,等待几秒钟(或等待用户输入),然后淡出,下一个场景加载. 组件源码 using UnityEngine; using System.Collections; // ...

  4. WPF:如何为程序添加splashScreen(初始屏幕)

    原文:http://www.cnblogs.com/chenxizhang/archive/2010/03/25/1694606.html 官网: https://msdn.microsoft.com ...

  5. Splashscreen

    Splashscreen Enables developers to show/hide the application's splash screen. Methods show hide Perm ...

  6. [Phonegap+Sencha Touch] 移动开发36 Phonegap/Cordova项目的图标和启动画面(splashscreen)配置

    原文地址:http://blog.csdn.net/lovelyelfpop/article/details/40780111 Phonegap/Cordova项目中的config.xml文件.里面配 ...

  7. WPF如何为程序添加splashScreen(初始屏幕)

    一.考虑到大部分的splashscreen其实都只是一个图片,所以最简单的做法是,先导入一张图片,然后设置它的生成操作为“splash screen” 二.通过程序设置SplashScreen pub ...

  8. WFP loading 窗口显示 SplashScreen

    public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { Spl ...

  9. winform 使用SplashScreen窗口

    SplashScreen,就是平时我们说的溅射屏幕,任何一个做过客户端程序的coder应该对它都不陌生,因为它能提升用户体验,让软件看上去更美.SplashScreenForm通常进入程序时是打开,主 ...

随机推荐

  1. 我的新发现:AVL树旋转的一个特性

    关于AVL树旋转的代码网络上铺天盖地. 一些经典的实现方法如下: AVLTree SingleLeftRotation(AVLTree A) { AVLTree B = A->left; A-& ...

  2. 使用NetBeans搭建基于Spring框架的Web应用

    NetBeans下载链接:https://netbeans.org/. 第一步:选择“文件”菜单下的“新建项目”: 第二步:类别选择“Java Web”,项目选择“Web应用程序”,单击“下一步”: ...

  3. Shell脚本关于屏幕输出的字符进行颜色控制的问题

    文本终端的颜色可以使用“ANSI非常规字符序列”来生成.举例: echo -e "\033[44;37;5m ME \033[0m COOL" 以上命令设置背景成为蓝色,前景白色, ...

  4. MFC通过ODBC方式连接mysql

    一. 要安装mysql-connector-odbc驱动 二. 配置数据源 电脑的控制面板-管理工具-数据源ODBC-系统DSN-添加-选择刚刚安装的mysql odbc Driver 参考 http ...

  5. Objective-C语言多态性

    动态类型和动态绑定,id可以表示任何指针类型,定义id变量不加* 多态性是指在父类中定义的成员变量和方法被子类继承之后,可以具有不同的数据类型或表现出不同的行为.这使得同一个变量和方法在父类及其各个子 ...

  6. apache+php+mysql的配置(转载)

    windows: 按http://jingyan.baidu.com/article/fcb5aff797ec41edaa4a71c4.html的安装 按http://www.jb51.net/art ...

  7. wex5 教程之 图文讲解 文件上传attachmentSimple(1)

    视频教程地址:http://v.youku.com/v_show/id_XMTc4NDAyMTY4OA==.html 效果预览: 1 调用attchmentSimple组件,打开文件管理器,并选中,显 ...

  8. dump_stack调用过程【原创】

    dump_stack调用: void dump_stack(void){    dump_backtrace(NULL, NULL);} 继续看: static void dump_backtrace ...

  9. 【转】MarshalAs属性和使用

    转载地址:http://blog.sina.com.cn/s/blog_4e4ee8ed0100elou.html [MarshalAs(UnmanagedType.ByValArray, SizeC ...

  10. JS事件整理

    onclick 鼠标点击事件 ondblclick 鼠标双击事件 onmouseover 鼠标移入事件 onmouseout 鼠标移出事件 onmousedown 鼠标按下事件 onmousemove ...