winform 使用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(1000);
SplashScreen.ChangeTitle("111");
Thread.Sleep(1000);
SplashScreen.ChangeTitle("222");
Thread.Sleep(1000);
SplashScreen.ChangeTitle("333");
Thread.Sleep(1000);
SplashScreen.ChangeTitle("444");
SplashScreen.Close();
}
}
}

winform 使用SplashScreen窗口的更多相关文章
- 借鉴网上的winform模仿QQ窗口停靠功能稍作改动
2015-07-11 15:24:04 1 using System; using System.Collections.Generic; using System.ComponentModel; u ...
- winform无边框窗口拖动
无边框的窗口想拖动,只需要在置顶的容器上添加对应的mousedown 和 mousemove 事件就可以实现了.代码如下: //拖动窗口 private Point mPoint = new Poin ...
- [WinForm]委托应用①——窗口之间方法/控件调用
不传参数 第二窗口:public partial class Form2 : Form { /// <summary> /// 定义委托 /// </summary> publ ...
- [Winform]无边框窗口悬浮右下角并可以拖拽移动
摘要 简单实现了一个这样的功能,程序启动时,窗口悬固定在右下角,并可以通过鼠标拖拽移动. 核心代码块 无边框窗口并不出现在任务栏 //无边框 this.FormBorderStyle = System ...
- Winform 多个窗口编辑同一条数据同步的实现
场景: 一个主窗口中,可以在列表(DataGridView)里选中一条记录编辑,打开一个编辑窗口(非模态窗口),编辑窗口保存后需要刷新父窗口,由于编辑窗口是非模态窗口,如果打开了多个窗口,并且都是编辑 ...
- 在wpf或winform关闭子窗口或对子窗口进行某个操作后刷新父窗口
父窗口: ///<summary> ///弹出窗口 ///</summary> ///<param name="sender"></pa ...
- WinForm窗体中窗口控件的生成
1:button控件的生成方式 Button button = new Button(); button.Size = new Size(80, 80); button.Location = new ...
- C#winform如何主窗口最大化最小化默认大小
this.WindowState = FormWindowState.Minimized; bool b = true; private void button2_Click(object sende ...
- Winform 无边框窗口移动自定义边框粗细颜色
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
随机推荐
- 【LOJbeta round1】ZQC的手办
NOI2012-超级钢琴的升级版. 用线段树维护最小值及其出现位置,接下来就跟超级钢琴一个做法了. #include<bits/stdc++.h> #define N 500010 #de ...
- 【Java基础】一些问题
1. HashSet是如何保证数据不重复的: 首先,HashSet添加元素的时候,底层是通过HashMap的put方法来实现的,而添加的元素,则是保存在了hashMap的key里,因为HashMap的 ...
- mysql远程访问cannot connect(10038) 问题解决的过程
今天用Navicat访问虚拟机上的mysql,无法访问报cannot connect(10038). 首先看是否可以telnet,本机cmd,telnet 192.168.209.128 3306,结 ...
- VS的使用
配置一个工程 问题描述: 要运行一个源码工程,工程中含有层级目录,.cpp与.h在多级目录中混合存储.并且该工程的运行依赖一些静态库(.lib)与动态库(.dll). 建立: 把.h拷贝至$(Proj ...
- python中的is, ==与对象的相等判断
在java中,对于两个对象啊a,b,若a==b表示,a和b不仅值相等,而且指向同一内存位置,若仅仅比较值相等,应该用equals.而在python中对应上述两者的是‘is’ 和‘==’. (1) py ...
- 怎么WordPress增加在线投稿功能
现在很多个人博客为了增加博客的内容,都会提供投稿通道,大部分都是以邮箱的形式进行投稿,不过这样一来,也很费人力,要拷贝复制,然后编辑等.如果给博客加个在线投稿功能,那就方便多了.稍微审核下文章内容就可 ...
- Laravel通过Swoole提升性能
1.安装配置laravel 1.1.composer下载laravel composer create-project --prefer-dist laravel/laravel blog " ...
- [Bootstrap]modal弹出框
写在前面 在实际开发中,为了友好,更需要一种美观的弹出框,js原生的alert,很难满足需求.这里推荐一个bootstrap的弹出框. 一个例子 先看效果吧 代码: <!DOCTYPE html ...
- 使用vue2.0 vue-router vuex 模拟ios7操作
其实你也可以,甚至做得更好... 首先看一下效果:用vue2.0实现SPA:模拟ios7操作 与 通讯录实现 github地址是:https://github.com/QRL909109/ios7 如 ...
- ASOP编译说明
具体说明https://source.android.com/source/ 源码下载https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/ 1 搭建编译环境使 ...