初次接触启动界面记不清是在哪一年了,估计是小学四年级第一次打开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. 一天一小段js代码(no.2)

    (一)可以用下面js代码来检测弹出窗口是否被屏蔽: var blocked = false ; try { /*window.open()方法接受4个参数window.open(要加载的url,窗口目 ...

  2. Comet实现的网页聊天程序

    “上一篇”介绍了我在c/s程序中用了那些技术,如今只谈c/s不谈b/s那未免out了,势必要写一写b/s的程序与大家共勉. 回忆做技术这些年,06年每天盯着“天轰穿”的视频不亦乐乎,估计那是一代程序员 ...

  3. 虚拟化平台cloudstack(4)——几个异常

    cloudstack主机添加不成功 CloudStack正常启动,添加区域.提供点和群集都正常,但是添加主机时提示添加不成功. 先添加主机: 然后出现提示: 在网上找了一圈,基本上没什么回复,没办法, ...

  4. Linux多线程系列-2-条件变量的使用(线程安全队列的实现)

    多线程情况下,往往需要使用互斥变量来实现线程间的同步,实现资源正确共享. linux下使用如下变量和函数 //条件变量 pthread_cond_t int pthread_cond_init (pt ...

  5. Python的枚举类型

    Python的 Python的没有我们有两种用法: 创建Enum的实例 创建Enum的subclass 创建Enum的实例 from enum import Enum, unique Month = ...

  6. 自动登录VSS

    每次打开vss都需要输入用户名.密码,用起来多少有些麻烦.用以下两种方式即可实现自动登录: 方法1: 在vss快捷方式的命令行最后面添加-y参数 "C:/Program Files/Micr ...

  7. Github快速入门手册

    最近在试用Github,开源的思想也让人觉得把一些经验分享出来是非常好的事情.附件是doc文件,如有需要请注意查收.希望能对你有帮助. GITHUB基于互联网的版本控制快速入门手册 如有不妥,欢迎指正 ...

  8. CSS伪类与CSS伪元素的区别及由来

    关于两者的区别,其实是很古老的问题.但是时至今日,由于各种网络误传以及一些不负责任的书籍误笔,仍然有相当多的人将伪类与伪元素混为一谈,甚至不乏很多CSS老手.早些年刚入行的时候,我自己也被深深误导,因 ...

  9. Uvaoj10054 - The Necklace

    /* 题意:打印欧拉回路! 思路:开始时不明白,dfs为什么是后序遍历? 因为欧拉回路本身是一条回路,那么我们在dfs时,可能存在提前找到回路,这条回路可能不是欧拉回路, 因为没有遍历完成所有的边!如 ...

  10. 如何利用Direct NFS克隆数据库

    CloneDB是Oracle 11.2.0.3推出的一项新特性,它利用的了11g新引入的Direct NFS.它直接利用目标数据库的备份,无需将备份COPY到克隆环境下,使得一个备份可以克隆多个不同用 ...