大部分常见的商业软件中都存在着欢迎界面,如微软公司的Office系列产品、Visual Stdio 2010等。
欢迎界面中通常显示软件的基本信息和产品的商标标识,当应用程序启动时间较长时,还可以在显示欢迎界面的同时加载应用程序,从而使得用户从心里上增加对程序加载时间的容忍度。
本例子的主要操作对象为窗体,即Form。其实使用的两个主要的窗体属性分别是StartPosition和FormBorderStyle。StartPosition属性用于控制窗体的起始位置,其中当设置为CenterScreen时即从屏幕的中央显示窗体。FormBorderStyle属性则用于控制窗体的外观。
namespace SplashScreen
{
public partial class SplashScreen : Form
{
public SplashScreen()
{
InitializeComponent();
}
private void SplashScreen_Load(object sender, EventArgs e)
{
this.ClientSize = this.BackgroundImage.Size;//是欢迎界面的大小和背景图片的大小相同。
}
}
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// SplashScreen
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = global::SplashScreen.Properties.Resources.Tulips;
this.ClientSize = new System.Drawing.Size(284, 262);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "SplashScreen";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "`";
this.Load += new System.EventHandler(this.SplashScreen_Load);
this.ResumeLayout(false); }
#endregion