初次接触启动界面记不清是在哪一年了,估计是小学四年级第一次打开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. Java提高篇(二七)-----TreeMap

    TreeMap的实现是红黑树算法的实现,所以要了解TreeMap就必须对红黑树有一定的了解,其实这篇博文的名字叫做:根据红黑树的算法来分析TreeMap的实现,但是为了与Java提高篇系列博文保持一致 ...

  2. FusionCharts简单教程(八)-----使用网格组件

            有时候我们会觉得使用图像不够直接,对于数据的显示没有表格那样直接明了.所以这里就介绍如何使用网格组件.将网格与图像结合起来.网格组件能够将FusionCharts中的单序列数据以列表的 ...

  3. C#最良心脚本语言C#Light/Evil,Xamarin\WP8\Unity热更新最良心方案,再次进化.

    C#Light的定位是嵌入式脚本语言,一段C#Light脚本是一个函数 C#Evil定位为书写项目的脚本语言,多脚本文件合作,可以完全用脚本承载项目. C#Light/Evil 使用完全C#一致性语法 ...

  4. Android按需添加Google Play服务

    以前无论使用何种Google Play服务,都是直接在gradle文件中引用一个库. compile 'com.google.android.gms:play-services:9.4.0' 这直接导 ...

  5. 如何选择前端框架:ANGULAR VS EMBER VS REACT

    最近一段时间是令前端工程师们非常兴奋的时期,因为三大Web框架陆续发布新版本,让我们见识到了更强大的Web框架.Ember2.0在2个月之前已经发布,从1.0升级到2.0非常简单.几周之前React发 ...

  6. Git bash 配置ssh key

    问题描述 昨天为了配置Qt create中的Git,把我一直在使用的Github删除了,今本以为,这样git的一些配置还在,可是,今天上传一些提交的时候,提示我,git没有密钥.梳理一下,这个简单的配 ...

  7. Qt控制台中文乱码问题

    本文主要记录了Qt控制台出现中文乱码的问题,一下列出了集中编码设置的方法.以前用VC6.0写的一个贪吃蛇的游戏,今天把源文件拿出来在Qt上面运行,出现中文乱码的问题.以前也遇到过,没想到小小的乱码,折 ...

  8. 品味FastDFS~目录

    回到占占推荐博客索引 参考文献:http://baike.baidu.com/view/973383.htm#sub5143372 分布式文件系统(DFS,Distributed File Syste ...

  9. 搭建jekyll博客

    使用jekyll将markdown文件生成静态的html文件,并使用主题有序的进行布局,形成最终的博客页面. 特点 基于ruby 使用Markdown书写文章 无需数据库 可以使用GitHub Pag ...

  10. JS中的匿名函数

    整理自:http://www.cnblogs.com/playerlife/archive/2012/10/17/2727683.html 一.什么是匿名函数? 在Javascript定义一个函数一般 ...