C#實現(xiàn)帶引導窗體的窗體設計操作流程
引言
很多時候。我們的窗體設計需要一個引導窗體。當打開一個項目的窗體時,默認的是先打開一個歡迎或介紹項目信息的引導窗體,幾秒鐘后再打開項目的主窗體。這幾秒時間最重要的意義是等待主窗體加載程序完畢。
1.設計操作流程
實現(xiàn)帶引導窗體的窗體設計操作流程:在項目里先設計兩個窗體,并把Form1改名為Frm_Main,把Form2改名為Frm_Start。切記在更改窗體名稱的時候按下ENTER確認此更改影響到了整個工程。
接著,把項目所需要的圖片資源設計到圖片資源管理器,并把圖片設計為相應窗體的背景,stretch。這一步的操作,詳見本文作者寫的其他文章。
進一步地,在Frm_Main窗體創(chuàng)建Load事件,在事件里定義Frm_Start的對象,并打開Frm_Start窗體。
進一步地,在Frm_Start窗體創(chuàng)建Load事件、設計Timer組件,并設計一個Tick事件,再創(chuàng)建一個FormClosed事件;在其Load事件中啟動定時器,設置定時器動作時間為10s,在定時器的Tick事件中設計為關閉窗體引導窗體;在其FormClosed事件設計為關閉定時器;
好了,至此符合項目需要的操作流程設計完畢,下面上代碼。
2.實例
(1)Resources.Designer.cs
//------------------------------------------------------------------------------ // <auto-generated> // 此代碼由工具生成。 // 運行時版本:4.0.30319.42000 // // 對此文件的更改可能會導致不正確的行為,并且如果 // 重新生成代碼,這些更改將會丟失。 // </auto-generated> //------------------------------------------------------------------------------ namespace _193.Properties { using System; /// <summary> /// 一個強類型的資源類,用于查找本地化的字符串等。 /// </summary> // 此類是由 StronglyTypedResourceBuilder // 類通過類似于 ResGen 或 Visual Studio 的工具自動生成的。 // 若要添加或移除成員,請編輯 .ResX 文件,然后重新運行 ResGen // (以 /str 作為命令選項),或重新生成 VS 項目。 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } /// <summary> /// 返回此類使用的緩存的 ResourceManager 實例。 /// </summary> [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_193.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } /// <summary> /// 重寫當前線程的 CurrentUICulture 屬性,對 /// 使用此強類型資源類的所有資源查找執(zhí)行重寫。 /// </summary> [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } /// <summary> /// 查找 System.Drawing.Bitmap 類型的本地化資源。 /// </summary> internal static System.Drawing.Bitmap C_編程詞典 { get { object obj = ResourceManager.GetObject("C_編程詞典", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } /// <summary> /// 查找 System.Drawing.Bitmap 類型的本地化資源。 /// </summary> internal static System.Drawing.Bitmap start { get { object obj = ResourceManager.GetObject("start", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } } }
(2)Frm_Main.Designer.cs
namespace _193 { partial class Frm_Main { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #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() { SuspendLayout(); // // Frm_Main // AutoScaleDimensions = new SizeF(7F, 17F); AutoScaleMode = AutoScaleMode.Font; BackgroundImage = Properties.Resources.C_編程詞典; BackgroundImageLayout = ImageLayout.Stretch; ClientSize = new Size(367, 238); Name = "Frm_Main"; Text = "軟件主界面"; Load += Frm_Main_Load; ResumeLayout(false); } #endregion } }
(3)Frm_Main.cs
namespace _193 { public partial class Frm_Main : Form { public Frm_Main() { InitializeComponent(); } private void Frm_Main_Load(object sender, EventArgs e) { Frm_Start frm = new(); frm.ShowDialog(); } } }
(4)Frm_Start.Designer.cs
namespace _193 { partial class Frm_Start { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #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() { components = new System.ComponentModel.Container(); timer1 = new System.Windows.Forms.Timer(components); SuspendLayout(); // // timer1 // timer1.Tick += Timer1_Tick; // // Frm_Start // AutoScaleDimensions = new SizeF(7F, 17F); AutoScaleMode = AutoScaleMode.Font; BackgroundImage = Properties.Resources.start; BackgroundImageLayout = ImageLayout.Stretch; ClientSize = new Size(368, 240); Name = "Frm_Start"; Text = "啟動界面"; FormClosed += Frm_Start_FormClosed; Load += Frm_Start_Load; ResumeLayout(false); } #endregion private System.Windows.Forms.Timer timer1; } }
(5)Frm_Start.cs
namespace _193 { public partial class Frm_Start : Form { public Frm_Start() { InitializeComponent(); } /// <summary> /// 啟動計時器,10s計時 /// </summary> private void Frm_Start_Load(object sender, EventArgs e) { timer1.Start(); timer1.Interval = 10000; } /// <summary> /// 關閉啟動窗體 /// </summary> private void Timer1_Tick(object sender, EventArgs e) { Close(); } /// <summary> /// 關閉計時器 /// </summary> private void Frm_Start_FormClosed(object sender, FormClosedEventArgs e) { timer1.Stop(); } } }
(6)生成效果
到此這篇關于C#實現(xiàn)帶引導窗體的窗體設計操作流程的文章就介紹到這了,更多相關C#引導窗體設計內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
在C#中使用二叉樹實時計算海量用戶積分排名的實現(xiàn)詳解
這篇文章主要介紹了在C#中使用二叉樹實時計算海量用戶積分排名的實現(xiàn)詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-01-01