C#實(shí)現(xiàn)帶引導(dǎo)窗體的窗體設(shè)計(jì)操作流程
引言
很多時(shí)候。我們的窗體設(shè)計(jì)需要一個(gè)引導(dǎo)窗體。當(dāng)打開一個(gè)項(xiàng)目的窗體時(shí),默認(rèn)的是先打開一個(gè)歡迎或介紹項(xiàng)目信息的引導(dǎo)窗體,幾秒鐘后再打開項(xiàng)目的主窗體。這幾秒時(shí)間最重要的意義是等待主窗體加載程序完畢。
1.設(shè)計(jì)操作流程
實(shí)現(xiàn)帶引導(dǎo)窗體的窗體設(shè)計(jì)操作流程:在項(xiàng)目里先設(shè)計(jì)兩個(gè)窗體,并把Form1改名為Frm_Main,把Form2改名為Frm_Start。切記在更改窗體名稱的時(shí)候按下ENTER確認(rèn)此更改影響到了整個(gè)工程。
接著,把項(xiàng)目所需要的圖片資源設(shè)計(jì)到圖片資源管理器,并把圖片設(shè)計(jì)為相應(yīng)窗體的背景,stretch。這一步的操作,詳見本文作者寫的其他文章。
進(jìn)一步地,在Frm_Main窗體創(chuàng)建Load事件,在事件里定義Frm_Start的對象,并打開Frm_Start窗體。
進(jìn)一步地,在Frm_Start窗體創(chuàng)建Load事件、設(shè)計(jì)Timer組件,并設(shè)計(jì)一個(gè)Tick事件,再創(chuàng)建一個(gè)FormClosed事件;在其Load事件中啟動(dòng)定時(shí)器,設(shè)置定時(shí)器動(dòng)作時(shí)間為10s,在定時(shí)器的Tick事件中設(shè)計(jì)為關(guān)閉窗體引導(dǎo)窗體;在其FormClosed事件設(shè)計(jì)為關(guān)閉定時(shí)器;
好了,至此符合項(xiàng)目需要的操作流程設(shè)計(jì)完畢,下面上代碼。
2.實(shí)例
(1)Resources.Designer.cs
//------------------------------------------------------------------------------ // <auto-generated> // 此代碼由工具生成。 // 運(yùn)行時(shí)版本:4.0.30319.42000 // // 對此文件的更改可能會(huì)導(dǎo)致不正確的行為,并且如果 // 重新生成代碼,這些更改將會(huì)丟失。 // </auto-generated> //------------------------------------------------------------------------------ namespace _193.Properties { using System; /// <summary> /// 一個(gè)強(qiáng)類型的資源類,用于查找本地化的字符串等。 /// </summary> // 此類是由 StronglyTypedResourceBuilder // 類通過類似于 ResGen 或 Visual Studio 的工具自動(dòng)生成的。 // 若要添加或移除成員,請編輯 .ResX 文件,然后重新運(yùn)行 ResGen // (以 /str 作為命令選項(xiàng)),或重新生成 VS 項(xiàng)目。 [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 實(shí)例。 /// </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> /// 重寫當(dāng)前線程的 CurrentUICulture 屬性,對 /// 使用此強(qiáng)類型資源類的所有資源查找執(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 = "啟動(dòng)界面"; 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> /// 啟動(dòng)計(jì)時(shí)器,10s計(jì)時(shí) /// </summary> private void Frm_Start_Load(object sender, EventArgs e) { timer1.Start(); timer1.Interval = 10000; } /// <summary> /// 關(guān)閉啟動(dòng)窗體 /// </summary> private void Timer1_Tick(object sender, EventArgs e) { Close(); } /// <summary> /// 關(guān)閉計(jì)時(shí)器 /// </summary> private void Frm_Start_FormClosed(object sender, FormClosedEventArgs e) { timer1.Stop(); } } }
(6)生成效果
到此這篇關(guān)于C#實(shí)現(xiàn)帶引導(dǎo)窗體的窗體設(shè)計(jì)操作流程的文章就介紹到這了,更多相關(guān)C#引導(dǎo)窗體設(shè)計(jì)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
在C#中使用二叉樹實(shí)時(shí)計(jì)算海量用戶積分排名的實(shí)現(xiàn)詳解
這篇文章主要介紹了在C#中使用二叉樹實(shí)時(shí)計(jì)算海量用戶積分排名的實(shí)現(xiàn)詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01C#自動(dòng)類型轉(zhuǎn)換與強(qiáng)制類型轉(zhuǎn)換的講解
今天小編就為大家分享一篇關(guān)于C#自動(dòng)類型轉(zhuǎn)換與強(qiáng)制類型轉(zhuǎn)換的講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-01-01C#實(shí)現(xiàn)過濾html標(biāo)簽并保留a標(biāo)簽的方法
這篇文章主要介紹了C#實(shí)現(xiàn)過濾html標(biāo)簽并保留a標(biāo)簽的方法,文中的自定義函數(shù)采用正則過濾實(shí)現(xiàn)了該功能,是非常實(shí)用的技巧,需要的朋友可以參考下2014-09-09C#提高編程能力的50個(gè)要點(diǎn)總結(jié)
這篇文章主要介紹了C#提高編程能力的50個(gè)要點(diǎn),較為詳細(xì)的總結(jié)分析了C#程序設(shè)計(jì)中常見的注意事項(xiàng)與編程技巧,需要的朋友可以參考下2016-02-02比較2個(gè)datatable內(nèi)容是否相同的方法
這篇文章主要介紹了比較2個(gè)datatable內(nèi)容是否相同的方法,大家參考使用吧2014-01-01