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窗口的更多相关文章

  1. 借鉴网上的winform模仿QQ窗口停靠功能稍作改动

    2015-07-11 15:24:04 1 using System; using System.Collections.Generic; using System.ComponentModel; u ...

  2. winform无边框窗口拖动

    无边框的窗口想拖动,只需要在置顶的容器上添加对应的mousedown 和 mousemove 事件就可以实现了.代码如下: //拖动窗口 private Point mPoint = new Poin ...

  3. [WinForm]委托应用①——窗口之间方法/控件调用

    不传参数 第二窗口:public partial class Form2 : Form { /// <summary> /// 定义委托 /// </summary> publ ...

  4. [Winform]无边框窗口悬浮右下角并可以拖拽移动

    摘要 简单实现了一个这样的功能,程序启动时,窗口悬固定在右下角,并可以通过鼠标拖拽移动. 核心代码块 无边框窗口并不出现在任务栏 //无边框 this.FormBorderStyle = System ...

  5. Winform 多个窗口编辑同一条数据同步的实现

    场景: 一个主窗口中,可以在列表(DataGridView)里选中一条记录编辑,打开一个编辑窗口(非模态窗口),编辑窗口保存后需要刷新父窗口,由于编辑窗口是非模态窗口,如果打开了多个窗口,并且都是编辑 ...

  6. 在wpf或winform关闭子窗口或对子窗口进行某个操作后刷新父窗口

    父窗口: ///<summary> ///弹出窗口  ///</summary> ///<param name="sender"></pa ...

  7. WinForm窗体中窗口控件的生成

    1:button控件的生成方式 Button button = new Button(); button.Size = new Size(80, 80); button.Location = new ...

  8. C#winform如何主窗口最大化最小化默认大小

    this.WindowState = FormWindowState.Minimized; bool b = true; private void button2_Click(object sende ...

  9. Winform 无边框窗口移动自定义边框粗细颜色

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

随机推荐

  1. python基础===利用PyCharm进行Python远程调试(转)

    原文链接:利用PyCharm进行Python远程调试 背景描述 有时候Python应用的代码在本地开发环境运行十分正常,但是放到线上以后却出现了莫名其妙的异常,经过再三排查以后还是找不到问题原因,于是 ...

  2. 64_d1

    DSDP-5.8-15.fc26.i686.rpm 13-Feb-2017 22:06 658926 DSDP-5.8-15.fc26.x86_64.rpm 13-Feb-2017 22:09 653 ...

  3. C# 对后台方法事件,可以直接return; 跳出

    protected void lbtButton_Click(object sender, EventArgs e) { return; } C# 对后台方法事件,可以直接return; 跳出

  4. 【ZJOI2016】大森林

    这题理论上可以用ETT,但是用LCT建虚点可以解决这个问题. 对于最晚的操作1建立一个虚点,然后把操作0挂上去. #include<bits/stdc++.h> ; using names ...

  5. aspxpivotgrid 导出excel时,非绑定咧显示为0的情况

    using DevExpress.XtraPrinting; Exporter.ExportXlsToResponse(this.Title,TextExportMode.Text,true); // ...

  6. 面试题之实现系统函数系列一:实现memmove函数

    编译环境 本系列文章所提供的算法均在以下环境下编译通过. [算法编译环境]Federa 8,linux 2.6.35.6-45.fc14.i686 [处理器] Intel(R) Core(TM)2 Q ...

  7. golang fmt格式占位符

    golang 的fmt 包实现了格式化I/O函数,类似于C的 printf 和 scanf. # 定义示例类型和变量 type Human struct { Name string } var peo ...

  8. 一个大div里面包裹一个小div,里面的小div的点击事件不触发外面的这个大div的点击事件

    一开始上html代码 <div id="div1" style="background: blue;width: 100px; height: 100px;&quo ...

  9. 《深入浅出MyBatis技术原理与实战》——1.简介,2.入门

    1. 简介 Java程序都是通过JDBC连接数据库,但是只定义了接口规范,具体的实现交给各个数据库厂商去实现,因为每个数据库都有其特殊性.所以JDBC是一种桥接模式. 这里为什么说JDBC是一种桥接模 ...

  10. 【JBPM4】任务节点-任务分配assignment-Handler

    JPDL <?xml version="1.0" encoding="UTF-8"?> <process key="task&quo ...