我也来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通常进入程序时是打开,主 ...
随机推荐
- Android -- 自定义View小Demo,绘制四位数随机码(一)
1,现在有这样一个需求,实现显示随机随机数可能在代码中直接很简单的就实现了,但是现在我们直接自定义View来实现这个效果,那么我们来分析一波吧,我们允许开发者自己设置这个textview的大小,颜色, ...
- 夺命雷公狗-----React---10--组建嵌套进行数据遍历
先写一个组建... 然后进行嵌套.. <!DOCTYPE html> <html lang="en"> <head> <meta char ...
- php递归无限极分类实例
无限级分类原理简介 无限分类看似"高大上",实际上原理是非常简单的 .无限分类不仅仅需要代码的巧妙性,也要依托数据库设计的合理性.要满足无限级分类,数据库需要有两个必须的字段,id ...
- javascript中的自增与自减
一直都对自增与自减的执行顺序有点糊涂,今天查了资料,来总结一下 a++(a--),就是指当时计算a,当下一次使用这个变量的时候才执行++或者-- ++a(--a),就是指当时就计算++或者-- 例1: ...
- case while for
#!/bin/bash#create by howhy 20161214#mysql server start stop restart. /etc/init.d/functionsmysqldir= ...
- master page
<?xml version="1.0"?><configuration> <system.web> <pages clientID ...
- 如何反编译DLL文件
1.利用反编译器,多种工具,本次选用Reflector 8.5. 2.界面如下:
- latex 异或
用\lxor \(\lxor\) 用\veebar \(\veebar\) 用\oplus \(\oplus\) ... 怎么不是我想象的那样... 算了.
- c++11中的for简化用法
1.序列for循环 map<string,int> m{{"a",1},{"b",2},{"c",3}} for(auto p: ...
- c语言头文件中定义全局变量的问题
c语言头文件中定义全局变量的问题 (转http://www.cnblogs.com/Sorean/) 先说一下,全局变量只能定义在 函数里面,任意函数,其他函数在使用的时候用extern声明.千万不要 ...