1.需要添加对Microsoft.VisualBasic 引用,

2.准备frmMain,frmSplash两个窗口

说明:
        frmSplash在主线程上建立,但是在独立线程上进行消息循环
        当protected override void OnCreateMainForm  方法执行完毕,会隐藏frmSplash
        可以在OnCreateMainForm中执行预加载操作,或者在frmMain的构造里执行,不要在frmMain的OnLoad事件中进行
        当需要改边frmSplash窗体上控件属性时(如显示加载提示等)需要使用控件的Invoke

using System;
using System.Collections.Generic;
using System.Windows.Forms; namespace SplashLoader
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(String[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
new SplashApp().Run(args);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualBasic.ApplicationServices;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Reflection;
using System.Configuration;
using ISplashLoader; namespace SplashLoader
{
public class SplashApp : WindowsFormsApplicationBase
{ private frmSplash _frmSplash = null; protected override void OnCreateSplashScreen()
{
//在主UI线程上运行
Console.WriteLine("OnCreateSplashScreen:" + Thread.CurrentThread.ManagedThreadId);
//这里调用是在主线程上的
//但是SplashForm的消息循环是在独立线程上的
//可以在SplashForm的OnLoad事件中看到是一个独立的线程
//因此OnCreateMainForm即使阻塞了,SplashForm也能正常绘制
//可以把数据初试化操作放在frmMain的构造函数中
//但是不要放在OnLoad事件中,因为在OnLoad时UI界面已经绘制完成
//如果在里面放置一些阻塞型的操作会导致界面卡死
//SplashForm在frmMain的OnLoad调用时隐藏(没有发现调用close事件--会有短暂延迟)
//
_frmSplash = new frmSplash();
SplashScreen = _frmSplash; SplashScreen.ShowInTaskbar = false;
SplashScreen.Cursor = System.Windows.Forms.Cursors.AppStarting;
} private bool CheckUpgrade()
{
if (this.CommandLineArgs.Count > )
{
if (string.Compare(CommandLineArgs[], "Upgrade:Skip", true) == )
{
return false;
}
}
return true;
}
protected override void OnCreateMainForm()
{
try
{ //在主UI线程上运行
Console.WriteLine("OnCreateMainForm:" + Thread.CurrentThread.ManagedThreadId); //注意使用SplashForm 后,可以在主窗体的构造中加载数据
//或者在SplashApp的OnCreateMainForm()中,不要放在frmMain的OnLoad事件中 if (CheckUpgrade())
{ _frmSplash.SetTips("检测是否有新的版本..."); Process pa = new Process();
pa.StartInfo.UseShellExecute = false;
pa.StartInfo.FileName = Path.Combine(Application.StartupPath, @"UpdateApp.exe");
pa.StartInfo.Arguments = "AppStart";
pa.Start();
while (!pa.HasExited) ; } String assembley = ConfigurationManager.AppSettings["MainAssembly"];
String type = ConfigurationManager.AppSettings["MainForm"];
MainForm = CreateForm(assembley, type, _frmSplash); }
catch (Exception e)
{
//处理动态加载过程中的异常
MessageBox.Show(e.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
} } /// <summary>
/// 动太加载窗体
/// </summary>
/// <param name="assembly">如:FIStudio.WinUI.(exe|dll)</param>
/// <param name="type">FIStudio.WinUI.UI.frmCooperatorMgr</param>
/// <returns></returns>
private Form CreateForm(String assembly,String type,ILoadTips loadTips)
{
String a = System.IO.Path.GetFileNameWithoutExtension(assembly);
Type t = Assembly.Load(a).GetType(type, true);
Form frm = Activator.CreateInstance(t, new Object[] { loadTips }) as Form;
return frm;
} }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using ISplashLoader; namespace SplashLoader
{
public partial class frmSplash : Form ,ILoadTips
{
public frmSplash()
{
InitializeComponent();
BackgroundImageLayout = ImageLayout.Stretch;
FormBorderStyle = FormBorderStyle.None;
StartPosition = FormStartPosition.CenterScreen;
Console.WriteLine("SplashForm:" + Thread.CurrentThread.ManagedThreadId);
}
delegate void SetTipsHandle(String tips);
public void SetTips(String tips)
{
if (lblTips.InvokeRequired)
{
lblTips.Invoke(new SetTipsHandle(SetTips), tips);
}
else
{
lblTips.Text = tips;
}
}
private void frmSplash_Load(object sender, EventArgs e)
{
Console.WriteLine("SplashForm_Load:" + Thread.CurrentThread.ManagedThreadId);
}
}
}

Demo:参考华为网盘/软件测试与任务/引导窗体

使用WindowsFormsApplicationBase实现引导界面的更多相关文章

  1. App 引导界面

    App 引导界面 1.前言 最近在学习实现App的引导界面,本篇文章对设计流程及需要注意的地方做一个浅显的总结. 附上项目链接,供和我水平类似的初学者参考——http://files.cnblogs. ...

  2. android——利用SharedPreference做引导界面

    很久以前就接触过sharedPreference这个android中的存储介质.但是一直没有实际使用过,今天在看之前做的“民用机型大全”的app时,突然想到可以使用sharedPreference类来 ...

  3. 【Android UI设计与开发】第05期:引导界面(五)实现应用程序只启动一次引导界面

    [Android UI设计与开发]第05期:引导界面(五)实现应用程序只启动一次引导界面 jingqing 发表于 2013-7-11 14:42:02 浏览(229501) 这篇文章算是对整个引导界 ...

  4. Android UI开发第四十一篇——墨迹天气3.0引导界面及动画实现

    周末升级了墨迹天气,看着引导界面做的不错,模仿一下,可能与原作者的代码实现不一样,但是实现的效果还是差不多的.先分享一篇以前的文章,android动画的基础知识,<Android UI开发第十二 ...

  5. 【Android UI设计与开发】3.引导界面(三)实现应用程序只启动一次引导界面

    大部分的引导界面基本上都是千篇一律的,只要熟练掌握了一个,基本上也就没什么好说的了,要想实现应用程序只启动一次引导界面这样的效果,只要使用SharedPreferences类,就会让程序变的非常简单, ...

  6. 【Android】首次进入应用时加载引导界面

    参考文章: [1]http://blog.csdn.net/wsscy2004/article/details/7611529 [2]http://www.androidlearner.net/and ...

  7. SharedPreference 存储小量数据,一般首次启动显示引导界面就用这个。

    写://添加一个SharedPreference并传入数据SharedPreference sharedPreferences = getSharedPreferences("share_d ...

  8. 转-ViewPager组件(仿微信引导界面)

    http://www.cnblogs.com/lichenwei/p/3970053.html 这2天事情比较多,都没时间更新博客,趁周末,继续继续~ 今天来讲个比较新潮的组件——ViewPager ...

  9. 【笔记】WPF实现ViewPager引导界面效果及问题汇总

    最近在开发项目的首次使用引导界面时,遇到了问题,引导界面类似于安卓手机ViewPager那样的效果,希望通过左右滑动手指来实现切换不同页面,其间伴随动画. 实现思路: 1.界面布局:新建一个UserC ...

随机推荐

  1. centos7下Firewall使用详解

    安装它,只需 # yum install firewalld如果需要图形界面的话,则再安装# yum install firewall-config 一.介绍 防火墙守护 firewalld 服务引入 ...

  2. GNU Radio: Overview of the GNU Radio Scheduler

    Scetion 1: The Flowgraph The flowgraph moves data from sources into sinks. 一个流图由多个模块组成,其中一般包括信源(Sour ...

  3. 关于 android 环信无法正确获取昵称的问题

    本案例中 username 记录成 userId了, nick 始终为空...,这是 getNick() 取得的就是 username..... 如果想自己取得自己系统的nickname则 做以下调整 ...

  4. [DP题]放苹果

    放苹果(DP做法) 描述 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法.输入第一行是测试数据的数目t(0 < ...

  5. bzoj 4069~4071 APIO2015

    T1 从高到底按位确定答案 A=1时f[i]表示前i个数合法的划分至少需要分出几段,时间复杂度$O(n^2log(ans))$ A>1时f[i][j]表示前i个数划分为j段是否可能合法,转移显然 ...

  6. postman全方位讲解(有空看下)

    Postman 接口测试神器 Postman 是一个接口测试和 http 请求的神器,非常好用. 官方 github 地址: https://github.com/postmanlabs Postma ...

  7. Train-Alypay-Cloud

    ylbtech-Train-Alypay-Cloud: 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   7.返回顶部   8.返回顶部 ...

  8. mysql迁移之巨大数据量快速迁移方案

    mysql迁移之巨大数据量快速迁移方案-增量备份及恢复 --chenjianwen 一.前言: 当mysql库的大小达到几十个G或者上百G,迁移起来是一件非常费事的事情,业务中断,导出导入耗费大量的时 ...

  9. pandas read_csv读取大文件的Memory error问题

    今天在读取一个超大csv文件的时候,遇到困难:首先使用office打不开然后在python中使用基本的pandas.read_csv打开文件时:MemoryError 最后查阅read_csv文档发现 ...

  10. js 各种距离

    网页可见区域宽  document.body.clientWidth  网页可见区域高  document.body.clientHeight  网页可见区域宽(包括边线的宽)  document.b ...