C#實現(xiàn)帶引導(dǎo)窗體的窗體設(shè)計操作流程
引言
很多時候。我們的窗體設(shè)計需要一個引導(dǎo)窗體。當(dāng)打開一個項目的窗體時,默認(rèn)的是先打開一個歡迎或介紹項目信息的引導(dǎo)窗體,幾秒鐘后再打開項目的主窗體。這幾秒時間最重要的意義是等待主窗體加載程序完畢。
1.設(shè)計操作流程
實現(xiàn)帶引導(dǎo)窗體的窗體設(shè)計操作流程:在項目里先設(shè)計兩個窗體,并把Form1改名為Frm_Main,把Form2改名為Frm_Start。切記在更改窗體名稱的時候按下ENTER確認(rèn)此更改影響到了整個工程。
接著,把項目所需要的圖片資源設(shè)計到圖片資源管理器,并把圖片設(shè)計為相應(yīng)窗體的背景,stretch。這一步的操作,詳見本文作者寫的其他文章。
進(jìn)一步地,在Frm_Main窗體創(chuàng)建Load事件,在事件里定義Frm_Start的對象,并打開Frm_Start窗體。
進(jìn)一步地,在Frm_Start窗體創(chuàng)建Load事件、設(shè)計Timer組件,并設(shè)計一個Tick事件,再創(chuàng)建一個FormClosed事件;在其Load事件中啟動定時器,設(shè)置定時器動作時間為10s,在定時器的Tick事件中設(shè)計為關(guān)閉窗體引導(dǎo)窗體;在其FormClosed事件設(shè)計為關(guān)閉定時器;
好了,至此符合項目需要的操作流程設(shè)計完畢,下面上代碼。
2.實例
(1)Resources.Designer.cs
//------------------------------------------------------------------------------
// <auto-generated>
// 此代碼由工具生成。
// 運(yùn)行時版本:4.0.30319.42000
//
// 對此文件的更改可能會導(dǎo)致不正確的行為,并且如果
// 重新生成代碼,這些更改將會丟失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace _193.Properties {
using System;
/// <summary>
/// 一個強(qiáng)類型的資源類,用于查找本地化的字符串等。
/// </summary>
// 此類是由 StronglyTypedResourceBuilder
// 類通過類似于 ResGen 或 Visual Studio 的工具自動生成的。
// 若要添加或移除成員,請編輯 .ResX 文件,然后重新運(yùn)行 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>
/// 重寫當(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 = "啟動界面";
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>
/// 關(guān)閉啟動窗體
/// </summary>
private void Timer1_Tick(object sender, EventArgs e)
{
Close();
}
/// <summary>
/// 關(guān)閉計時器
/// </summary>
private void Frm_Start_FormClosed(object sender, FormClosedEventArgs e)
{
timer1.Stop();
}
}
}(6)生成效果


到此這篇關(guān)于C#實現(xiàn)帶引導(dǎo)窗體的窗體設(shè)計操作流程的文章就介紹到這了,更多相關(guān)C#引導(dǎo)窗體設(shè)計內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
在C#中使用二叉樹實時計算海量用戶積分排名的實現(xiàn)詳解
這篇文章主要介紹了在C#中使用二叉樹實時計算海量用戶積分排名的實現(xiàn)詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01
C#自動類型轉(zhuǎn)換與強(qiáng)制類型轉(zhuǎn)換的講解
今天小編就為大家分享一篇關(guān)于C#自動類型轉(zhuǎn)換與強(qiáng)制類型轉(zhuǎn)換的講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-01-01
C#實現(xiàn)過濾html標(biāo)簽并保留a標(biāo)簽的方法
這篇文章主要介紹了C#實現(xiàn)過濾html標(biāo)簽并保留a標(biāo)簽的方法,文中的自定義函數(shù)采用正則過濾實現(xiàn)了該功能,是非常實用的技巧,需要的朋友可以參考下2014-09-09

