初次接触启动界面记不清是在哪一年了,估计是小学四年级第一次打开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. ASP.NET集成模式下的管道事件

  2. js中setTimeout()的使用bug

    今天用setTimeout()时,遇到一个奇怪的现象,通过多方面的查询,最终解决了问题,这是setTimeout()设计的时候存在的一点点bug. 代码的作用主要是在三秒后自动关闭本浏览器窗口: 代码 ...

  3. 为什么eclipse中启动tomcat后,浏览器中出现404?

    问题描述: tomcat压缩包加压后,启动lib文件夹下面的startup.bat,在浏览器中输入http://localhost:8080/后出现熟悉的界面. 但是在eclipse中,jsp可以正常 ...

  4. rewrite规则写法及nginx配置location总结

    rewrite只能放在server{},location{},if{}中,并且只能对域名后边的除去传递的参数外的字符串起作用. 例如http://seanlook.com/a/we/index.php ...

  5. Atitit 图像处理30大经典算法attilax总结

    Atitit 图像处理30大经典算法attilax总结 1. 识别模糊图片算法2 2. 相似度识别算法(ahash,phash,dhash)2 3. 分辨率太小图片2 4. 横条薯条广告2 5. 图像 ...

  6. document对象

    document 对象是操作网页内容的 找元素 1.根据id找 document.getElementById(); 2.根据class找 document.getElementsByClassNam ...

  7. javascript_core_02之函数、作用域

    1.函数:封装一项任务步骤清单的代码段: ①声明:function 函数名(参数列表){ 步骤清单代码:return 返回值:} ②返回值:使调用者获得函数执行结果,return只返回,不保存: ③存 ...

  8. 查看Query Plan

    在执行一个查询语句时,查询优化器编译查询语句,产生一个足够好的Compiled Plan,将其缓存到plan cache中.Compiled plan是基于batch的,如果一个batch含有多个qu ...

  9. Design5:Sql server 文件组和文件

    1,文件组和文件的作用 Sql Server的数据存储在文件中,文件是实际存储数据的物理实体,文件组是逻辑对象,Sql server通过文件组来管理文件. 一个DataBase有一个或多个FileGr ...

  10. 文本溢出text-overflow和文本阴影text-shadow

    前面的话 CSS3新增了一些关于文本的样式,其中text-overflow文本溢出和text-shadow文本阴影有些特别.因为它们有对应的overflow溢出属性和box-shadow盒子阴影属性. ...