初次接触启动界面记不清是在哪一年了,估计是小学四年级第一次打开Office Word的时候吧,更记不清楚当时的启动界面是长啥样了。后来随着使用的软件越来越多,也见到各式各样的启动界面。下面就列举了两个平常本人平常最常见的窗体,其实windows系统在启动的过程中,有Window字样并且有动画效果的那个节面也算是一个启动界面。

  其目的很明显,就是程序启动之后,由于加载主界面的时间过长而导致用户体验不佳,于是往往在显示主界面之前多显示一个不带windows窗体元素的窗体,来显示应用程序加载的进度或者直接是一个静态的视图,作用在于就是跟用户反映程序是有响应的并且正在运行当中,从而提高用户体验。下面是我的载入窗

主要是仿照了Office 2013的风格

  简约明了。其中窗体的底色,字体,文字颜色可以更改,左上角的制造商,中间的软件名称,左下角的进度信息都可以更改。不过暂时还没有把图标附加到左上角而已。

窗体的设计如下所示

  载入窗的制造商,软件名称这些信息通过构造函数传参进行设置,此外默认的构造函数被屏蔽了

         private LoadingForm()
{
InitializeComponent();
} public LoadingForm(string logoStr, string appNameStr, string iniMsgStr):this()
{
this.lbLogo.Text = logoStr;
AppName = appNameStr;
this.lbMsg.Text = iniMsgStr;
this.picLoading.Width = this.Width; this.MouseDown+=new MouseEventHandler(LoadingForm_MouseDown);
foreach (Control con in this.Controls)
{
if (con.Equals(this.btnClose)) continue;
con.MouseDown += new MouseEventHandler(LoadingForm_MouseDown);
}
}

  对窗体的打开并非用单纯的Show或者ShowDialog,因为在主线程上Show的话,本身主线程要加载时就会阻塞,这样再阻塞的线程上show的话,窗体难以显示。如果用ShowDialog的也不行,虽然它可以让窗体显示出来,但是调用了ShowDialog之后直到窗体关闭了才返回。就是说载入窗关闭了之后才执行载入加载之类的操作,这样显得毫无意义。

  这里只是用来了一个异步去ShowDialog。代码如下

         public void ShowLoading()
{
Action callback = new Action(delegate()
{
if (!this.IsDisposed)
this.ShowDialog();
});
callback.BeginInvoke(null, null);
}

  这里在ShowDialog之前还多作了一个判断,在于关闭窗体的方法时释放了资源,因此在几个地方都要注意,关闭窗体的处理如下

         public void CloseLoading()
{
if (!this.IsDisposed && this.IsHandleCreated)
{
this.Invoke((Action)delegate
{
this.Close();
this.Dispose(); });
}
}

  由于调用了Invoke,这个需要判断当前窗体是否已经是显示了出来,否则就会因为窗体的句柄不存在而抛出异常。

  在窗体上显示的进度信息,只是通过了一个外放的属性实现,其判断的用意跟关闭窗体时的一样。

         public string Message {
get { return this.lbMsg.Text; }
set
{
if (!this.IsDisposed&&this.IsHandleCreated)
{
this.Invoke((Action)delegate()
{
this.lbMsg.Text = value;
});
}
}
}

为了窗体能具备可拖拽的效果,还额外加了一下的代码

         [DllImport("user32.dll")]
private static extern bool ReleaseCapture();
[DllImport("user32.dll")]
private static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MOVE = 0xF010;
private const int HTCAPTION = 0x0002; protected void LoadingForm_MouseDown(object sender, MouseEventArgs e)
{ ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, );
}

调用的形式如下

            LoadingForm frm = new LoadingForm("HopeGi", "猴健工具集", "启动中...");
frm.ShowLoading();
//一系列操作
frm.Message = "加载界面...";
//一系列操作
frm.CloseLoading();

  最近出了点状况,电脑很久也没碰了,前进的步伐缓了下来。能写出来的博客也不咋的,各位有什么好的建议和意见尽管提,谢谢!最后附上源码,可是用到的gif图片没附带上来

     public partial class LoadingForm : Form
{ [DllImport("user32.dll")]
private static extern bool ReleaseCapture();
[DllImport("user32.dll")]
private static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MOVE = 0xF010;
private const int HTCAPTION = 0x0002; private LoadingForm()
{
InitializeComponent();
} public LoadingForm(string logoStr, string appNameStr, string iniMsgStr):this()
{
this.lbLogo.Text = logoStr;
AppName = appNameStr;
this.lbMsg.Text = iniMsgStr;
this.picLoading.Width = this.Width; this.MouseDown+=new MouseEventHandler(LoadingForm_MouseDown);
foreach (Control con in this.Controls)
{
if (con.Equals(this.btnClose)) continue;
con.MouseDown += new MouseEventHandler(LoadingForm_MouseDown);
}
} public string Message {
get { return this.lbMsg.Text; }
set
{
if (!this.IsDisposed&&this.IsHandleCreated)
{
this.Invoke((Action)delegate()
{
this.lbMsg.Text = value;
});
}
}
} public void ShowLoading()
{
Action callback = new Action(delegate()
{
if (!this.IsDisposed)
this.ShowDialog();
});
callback.BeginInvoke(null, null);
} public void CloseLoading()
{
if (!this.IsDisposed && this.IsHandleCreated)
{
this.Invoke((Action)delegate
{
this.Close();
this.Dispose(); });
}
} private string AppName {
get { return this.lbAppName.Text; }
set {
this.lbAppName.Text = value;
this.lbAppName.Location = new Point((this.Width - this.lbAppName.Width) / , this.lbAppName.Location.Y);
}
} private void btnClose_Click(object sender, EventArgs e)
{
this.CloseLoading();
Environment.Exit();
} protected void LoadingForm_MouseDown(object sender, MouseEventArgs e)
{ ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, );
} #region Windows Form Designer generated code /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lbLogo = new System.Windows.Forms.Label();
this.lbAppName = new System.Windows.Forms.Label();
this.lbMsg = new System.Windows.Forms.Label();
this.btnClose = new System.Windows.Forms.PictureBox();
this.picLoading = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.btnClose)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.picLoading)).BeginInit();
this.SuspendLayout();
//
// lbLogo
//
this.lbLogo.AutoSize = true;
this.lbLogo.Font = new System.Drawing.Font("楷体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.lbLogo.ForeColor = System.Drawing.Color.White;
this.lbLogo.Location = new System.Drawing.Point(, );
this.lbLogo.Name = "lbLogo";
this.lbLogo.Size = new System.Drawing.Size(, );
this.lbLogo.TabIndex = ;
this.lbLogo.Text = "LOGO";
//
// lbAppName
//
this.lbAppName.AutoSize = true;
this.lbAppName.Font = new System.Drawing.Font("黑体", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.lbAppName.ForeColor = System.Drawing.Color.White;
this.lbAppName.Location = new System.Drawing.Point(, );
this.lbAppName.Name = "lbAppName";
this.lbAppName.Size = new System.Drawing.Size(, );
this.lbAppName.TabIndex = ;
this.lbAppName.Text = "AppName\r\n";
//
// lbMsg
//
this.lbMsg.AutoSize = true;
this.lbMsg.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.lbMsg.ForeColor = System.Drawing.Color.White;
this.lbMsg.Location = new System.Drawing.Point(, );
this.lbMsg.Name = "lbMsg";
this.lbMsg.Size = new System.Drawing.Size(, );
this.lbMsg.TabIndex = ;
this.lbMsg.Text = "label1";
//
// btnClose
//
this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnClose.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnClose.Image = global::AllTypeTest.Properties.Resources.Delete;
this.btnClose.Location = new System.Drawing.Point(, );
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(, );
this.btnClose.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.btnClose.TabIndex = ;
this.btnClose.TabStop = false;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// picLoading
//
this.picLoading.Image = global::AllTypeTest.Properties.Resources.download;
this.picLoading.Location = new System.Drawing.Point(, );
this.picLoading.Name = "picLoading";
this.picLoading.Size = new System.Drawing.Size(, );
this.picLoading.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.picLoading.TabIndex = ;
this.picLoading.TabStop = false;
//
// LoadingForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.ForestGreen;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.btnClose);
this.Controls.Add(this.lbMsg);
this.Controls.Add(this.picLoading);
this.Controls.Add(this.lbAppName);
this.Controls.Add(this.lbLogo);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "LoadingForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "LoadingForm";
this.TopMost = true;
((System.ComponentModel.ISupportInitialize)(this.btnClose)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picLoading)).EndInit();
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Label lbLogo;
private System.Windows.Forms.Label lbAppName;
private System.Windows.Forms.PictureBox picLoading;
private System.Windows.Forms.Label lbMsg;
private System.Windows.Forms.PictureBox btnClose; }

LoadingForm

仿Office的程序载入窗体的更多相关文章

  1. 仿QQ聊天程序(java)

    仿QQ聊天程序 转载:牟尼的专栏 http://blog.csdn.net/u012027907 一.设计内容及要求 1.1综述 A.系统概述 我们要做的就是类似QQ这样的面向企业内部的聊天软件,基本 ...

  2. 小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载四(使用程序载入事件)

    在了解了PhoneGap中都有哪些事件之后,本节将開始对这些事件的使用方法进行具体地介绍.本节要介绍的是程序载入事件,也就是deviceready.pause和resume这3个事件. [范例4-2 ...

  3. 快速找到Office应用程序安装路径

    p{ font-size: 15px; } .alexrootdiv>div{ background: #eeeeee; border: 1px solid #aaa; width: 99%; ...

  4. 高仿Readhub小程序 微信小程序项目【原】

    # News #### 项目介绍微信小程序项目涉及功能 https://gitee.com/richard1015/News https://github.com/richard1015/News 高 ...

  5. C#WinForm窗体内Panel容器中嵌入子窗体、程序主窗体设计例子

    C#WinForm父级窗体内Panel容器中嵌入子窗体.程序主窗体设计例子 在项目开发中经常遇到父级窗体嵌入子窗体所以写了一个例子程序,顺便大概划分了下界面模块和配色,不足之处还望指点 主窗体窗体采用 ...

  6. C#程序实现窗体的最大化/最小化

    C#程序实现窗体的最大化/最小化 http://blog.csdn.net/jiangqin115/article/details/41251215 private void button1_Clic ...

  7. Office应用程序对照表

    任何Office应用程序(包括excel)的类型库都作为Office安装的一部分安装.类型库是特定于版本的(即,安装了哪个版本的Office). 例如,Office 2007版本为12.0,Offic ...

  8. 微信小程序--仿微信小程序朋友圈Pro(内容发布、点赞、评论、回复评论)

    微信小程序--仿微信小程序朋友圈Pro(内容发布.点赞.评论.回复评论) 项目开源地址M朋友圈Pro 求个Star 项目背景 ​ 基于原来的开源项目 微信小程序仿朋友圈功能开发(发布.点赞.评论等功能 ...

  9. winfrom 关闭别的应用程序的窗体或者弹出框(winform 关闭句柄)

    在word转换成html的时候,由于系统版本不一样,office总是抛出异常,Microsoft Word停止工作,下面有三个按钮,关闭程序等等,但是我的转换工作需要自动的,每当抛出异常的时候我的程序 ...

随机推荐

  1. 对map集合进行排序

          今天做统计时需要对X轴的地区按照地区代码(areaCode)进行排序,由于在构建XMLData使用的map来进行数据统计的,所以在统计过程中就需要对map进行排序. 一.简单介绍Map   ...

  2. [安卓] 14、安卓HTTP——POST和GET用法分析

    内容简介 本文通过建立一个简单的Servlet服务器来分析安卓上用HTTP和服务器通信的细节,旨在演示C/S模式下服务器端和客户端的工作过程. 目录 part.1 用MyEclipse建立一个简单的s ...

  3. CSDN CODE平台,中国版Github简要使用说明!(多图慎入)

    楼主说 以前一直看到别人在用github发布自己的代码,各种牛逼,各种羡慕嫉妒恨.最后终于受不了了,也去注册了一个,注册到没什么难度.然后就没有然后了... 完全看不懂,不知道怎么用. 一次偶然的机会 ...

  4. Flyway, 数据库Schema管理利器

    整天跟数据库打交道的程序员都知道,当数据库的Schema发生改变时是多么痛苦的事情.尤其是一个在不断开发完善的项目,随着需求变化,数据库的schema也会跟着变化,而追踪记录这些变化一向都是费时费力. ...

  5. 定时关闭AWS上的EC2机器实例

    最近一段时间在做一个产品从阿里云向亚马逊云中国区迁移的前期试验.亚马逊中国区并没有开放免费体验账号,使用的每一份资源都要实打实的掏钱.而为了实验我们使用时一般要启动好几台EC2实例.为了不浪费辛辛苦苦 ...

  6. ehcache2拾遗之copyOnRead,copyOnWrite

    问题描述 缓存在提升应用性能,提高访问效率上都是至关重要的一步.ehcache也是广为使用的缓存之一.但是如果将一个可变的对象(如普通的POJO/List/Map等)存入缓存中,会导致怎样潜在的问题. ...

  7. c基础回顾

    发现一个很好的c学习网站http://see.xidian.edu.cn/cpp/html/ 做了一些练习: #include <string.h> #include <stdio. ...

  8. 知方可补不足~sqlserver中的几把锁~续

    回到目录 之前写过相关的文章,对脏读,不可重复读,幻读都做了相当的研究,而今天在程序中又出现了这个问题,即当一条数据被update时,另一个线程同时发起了读的操作,这对于序列化级别的事务是不被允许的, ...

  9. 1.安装Redis

    首要条件:安装VMware,在虚拟机中安装CentOS. 安装步骤: 1.打开终端(Terminal) 2.在终端输入:wget http://download.redis.io/releases/r ...

  10. C++标准库vector类型详解

    Vector简介 vector是定义在C++标准模板库,它是一个多功能.能够操作多种数据结构和算法的模板类(关于模板类我们后面会介绍,如何创建自己的模板类).vector是一个容器,能够像容器一样存放 ...