我也来SplashScreen
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的更多相关文章
- 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 ...
- 设置 phoneGap/Cordova 3.4 应用程序启动动画闪屏 SplashScreen
当Cordova 程序打包并安装到手机中后,我们会发现启动程序时,会有数秒的黑屏现象,常见的解决方法则是设置闪屏后面. 这里以 Android 程序为例,介绍Cordova设置启动画面的方法. 1. ...
- Unity-WIKI 之 SplashScreen
组件功能 在屏幕上的一个启动画面消失,等待几秒钟(或等待用户输入),然后淡出,下一个场景加载. 组件源码 using UnityEngine; using System.Collections; // ...
- WPF:如何为程序添加splashScreen(初始屏幕)
原文:http://www.cnblogs.com/chenxizhang/archive/2010/03/25/1694606.html 官网: https://msdn.microsoft.com ...
- Splashscreen
Splashscreen Enables developers to show/hide the application's splash screen. Methods show hide Perm ...
- [Phonegap+Sencha Touch] 移动开发36 Phonegap/Cordova项目的图标和启动画面(splashscreen)配置
原文地址:http://blog.csdn.net/lovelyelfpop/article/details/40780111 Phonegap/Cordova项目中的config.xml文件.里面配 ...
- WPF如何为程序添加splashScreen(初始屏幕)
一.考虑到大部分的splashscreen其实都只是一个图片,所以最简单的做法是,先导入一张图片,然后设置它的生成操作为“splash screen” 二.通过程序设置SplashScreen pub ...
- WFP loading 窗口显示 SplashScreen
public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { Spl ...
- winform 使用SplashScreen窗口
SplashScreen,就是平时我们说的溅射屏幕,任何一个做过客户端程序的coder应该对它都不陌生,因为它能提升用户体验,让软件看上去更美.SplashScreenForm通常进入程序时是打开,主 ...
随机推荐
- STL之容器(1)
STL容器类的模板 容器部分主要由头文件<vector>,<list>,<deque>,<set>,<map>,<stack>和 ...
- Ruby(Selenium / Rspec)在Windows 8_64上安装步骤
1.首先需要下载RubyInstaller.exe程序(下载地址随便都能找到). 如:rubyinstaller-2.2.2-x64.exe 安装好Ruby后,需要更新Gems gem update ...
- ReferenceEquals和 == 和equals()的比较
对于这几点的区别网上经常有各种答案,而且常常会出现答案之间是互相矛盾的.要嘛就是根本含糊的解释不清楚,只是把测试结果扔上来并没有言简意赅的写出他们之间的比较.难道面试的时候考官问你,你也要在纸上写一大 ...
- 使用Redis分布式队列
1.这是处理异常的类 public class MyExceptionAttribute:HandleErrorAttribute { //public static Queue<Excepti ...
- mysql++的release版本当机的问题
今天用mysql++的release写例子,总是当机,仔细查了一下,发现在编mysqlpp库的时候,代码生成设置成了MDD,改成MD就好了.
- ubuntu 在mac 的 Parallels 的分辨率问题
安装 ubuntu系统,刚开始安装成功的时候分辨率只有800*600. 设置里面只有800*600一个选项. http://linuxbsdos.com/2014/10/31/solutions-fo ...
- OBD K线抓包 III
14230 HL激活, 5BPS又称 00 //电平激活 C1 33 F1 81 66 //14230的Enter命令 83 F1 11 C1 EF 8F C4 //回应了,一个命令就回应了... ...
- 利用ksoap调用webservice
博文参考: http://www.cnblogs.com/shenliang123/archive/2012/07/05/2578586.html http://blog.csdn.net/jimbo ...
- 读取NVRAM中的SN(barcode)
在Custom_NvRam_LID.h中,找到需要读取的ID对应的值 实现NvRAMAgent import java.lang.String; import android.os.RemoteExc ...
- ie11媒体查询以及其他hack
<!doctype html> <html> <head> <title>IE10/11 Media Query Test</title> ...