我也来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通常进入程序时是打开,主 ...
随机推荐
- PHP二维数组提取函数----把不需要的数据剔除
首先说明一些这个函数的应用场景,比如说你得到的数据是个二维数组,里面的很多成员其实是不必要的,比如说api调用后不必要给别人返回一些用不到的垃圾数据吧,如下是代码. <?php /* * del ...
- 2015弱校联盟(1) - C. Censor
C. Censor Time Limit: 2000ms Memory Limit: 65536KB frog is now a editor to censor so-called sensitiv ...
- 【Nginx】配置Nginx的负载均衡
参考的优秀文章 tomcat配置文件server.xml详解 AJP协议总结与分析 Using nginx as HTTP load balancer 在本机运行2个Tomcat 现需要运行两个Tom ...
- 我的android学习经历40
为listview设置背景,并且不随拖动改变 <ListView android:id="@+id/list_view" android:layout_width=" ...
- C# Global Application_Error不执行
今天在开发过程中遇到一个很奇特的问题,就是 Global 文件中的Application_Error 方法不执行的问题,很是苦恼,查了有关这方面的问题,感觉网友们回答的都有点乱,有些人说 在编译时不需 ...
- 8 个必备的PHP功能开发
做过PHP开发的程序员应该清楚,PHP中有很多内置的功能,掌握了它们,可以帮助你在做PHP开发时更加得心应手,本文将分享8个开发必备的PHP功能,个个都非常实用,希望各位PHP开发者能够掌握. ...
- linux应用程序开发-文件编程-系统调用方式
在看韦东山视频linux驱动方面有一些吃力,究其原因,虽然接触过linux应用程序编程,但是没有深入去理解,相关函数用法不清楚,正好看到国嵌视频对这一方面讲的比较透彻, 所以把学习过程记录下来,也作为 ...
- [Prodinner项目]学习分享_第二部分_Entity到DB表的映射
1.单纯映射 基本语法为 modelBuilder.Entity<InsType>().ToTable("TB_InsType"); 2.一对多映射(表关系) 实体类B ...
- 今天的感悟,对于python中的list()与w3c教程
首先本来想百度一下python定义列表的时候用 list()与直接用[]有什么区别,其中没有找到相关直接资料,看到了W3c菜鸟教程中之前看到的tuple,不禁想起list(tuple)是用来将元组转换 ...
- shader函数
Intrinsic Functions (DirectX HLSL) The following table lists the intrinsic functions available in HL ...