本文转自:http://www.smartgz.com/blog/Article/1088.asp

原文如下:

本代码可以依据主程序加载进度来显示Splash。

    static class Program
{
/// <summary>
/// 主程序的入口点在此设置,包括一些初始化操作,启动窗体等
/// </summary>
private static ApplicationContext context;
[STAThread]
static void Main()
{
Application.EnableVisualStyles(); //样式设置
Application.SetCompatibleTextRenderingDefault(false); //样式设置
Splash sp = new Splash(); //启动窗体
sp.Show(); //显示启动窗体
context = new ApplicationContext();
context.Tag = sp;
Application.Idle += new EventHandler(Application_Idle); //注册程序运行空闲去执行主程序窗体相应初始化代码
Application.Run(context);
} //初始化等待处理函数
private static void Application_Idle(object sender, EventArgs e)
{
Application.Idle -= new EventHandler(Application_Idle);
if (context.MainForm == null)
{
Main mw = new Main();
context.MainForm =mw;
mw.init(); //主窗体要做的初始化事情在这里,该方法在主窗体里应该申明为public
Splash sp = (Splash)context.Tag;
sp.Close(); //关闭启动窗体
mw.Show(); //启动主程序窗体
}
}
}

Splash窗体的相关属性设置:
        BackgroundImage:载入你想作为启动画面的图片;
        ControlBox:False;
        FormBorderStyle:None;
        ShowInTaskbar:False;
        StartPositon:CenterScreen.

[转] 
http://www.lordong.cn/blog/post/18.html 
当程序在启动过程中需要花一些时间去加载资源时,我们希望程序能显示一个欢迎界面,能简单介绍软件功能的同时还能告知用户该程序还在加载中,使得用户体验更友好。 
实现如下:

1. 添加欢迎界面的窗体(比如SlpashForm),做以下调整: 
将FormBorderStyle属性设成None,即没有窗体边框 
将StartPosition属性设成CenterScreen,即总是居中 
将TopMost属性设成True,即总是在顶部 
将UseWaitCursor属性设成Ture,即显示等待光标,让人感觉后台还在运行 
增加一个PictureBox控件,与欢迎图片大小一致,窗体的大小也设成一致 
增加一个ProgressBar控件,将Style设成Marquee,将MarqueeAnimationSpeed设成50

2. 主界面的构造函数改成以下代码:

// Create thread to show splash window
Thread showSplashThread = new Thread(new ThreadStart(ShowSplash));
showSplashThread.Start(); // Time consumed here
InitializeFrame(); // 把原来构造函数中的所有代码移到该函数中 // Abort show splash thread
showSplashThread.Abort();
showSplashThread.Join(); // Wait until the thread aborted
showSplashThread = null; . 显示SplashForm的线程函数
///
/// Thread to show the splash.
///
private void ShowSplash()
{
SplashForm sForm = null;
try
{
sForm = new SplashForm();
sForm.ShowDialog();
}
catch (ThreadAbortException e)
{
// Thread was aborted normally
if (_log.IsDebugEnabled)
{
_log.Debug("Splash window was aborted normally: " + e.Message);
}
}
finally
{
sForm = null;
}
}

4. 在主窗体的Load事件加激活自己的代码 
SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);

在使用SetForegroundWindow之前先声明一下 
// Uses to active the exist window 
[DllImport("User32.dll")] 
public static extern void SetForegroundWindow(IntPtr hwnd);

http://www.cnblogs.com/hcfalan/archive/2006/09/13/502730.html

对于需要加载很多组件的应用程序来说,在启动的时候会非常的缓慢,可能会让用户误以为程序已经死掉,这显然不是我们希望看到的。如果能够在启动的时候动态的给用户一些反馈信息(比如当前正在加载的项),那么就可以有效的避免这一问题,并且可以给我们的应用程序增色不少。下边的图片是此代码的效果图。
 
下面是部分代码:
AppStart 类,包含Main方法

public class AppStart
{
public AppStart()
{
}
[STAThread]
static void Main(string[] args)
{
// 显示Splash窗体
Splash.Show(); DoStartup(args); // 关闭Splash窗体
Splash.Close();
} static void DoStartup(string[] args)
{
// 做需要的事情
frmMain f = new frmMain();
Application.Run(f);
}
}

Splash功能类:

public class Splash
{
static frmSplash MySplashForm = null;
static Thread MySplashThread = null; static void ShowThread()
{
MySplashForm = new frmSplash();
Application.Run(MySplashForm);
} static public void Show()
{
if (MySplashThread != null)
return; MySplashThread = new Thread(new ThreadStart(Splash.ShowThread));
MySplashThread.IsBackground = true;
MySplashThread.ApartmentState = ApartmentState.STA;
MySplashThread.Start();
} static public void Close()
{
if (MySplashThread == null) return;
if (MySplashForm == null) return; try
{
MySplashForm.Invoke(new MethodInvoker(MySplashForm.Close));
}
catch (Exception)
{
}
MySplashThread = null;
MySplashForm = null;
} static public string Status
{
set
{
if (MySplashForm == null)
{
return;
} MySplashForm.StatusInfo = value;
}
get
{
if (MySplashForm == null)
{
throw new InvalidOperationException("Splash Form not on screen");
}
return MySplashForm.StatusInfo;
}
}
}

Splash 界面类:

public class frmSplash : System.Windows.Forms.Form
{
private string _StatusInfo = ""; public frmSplash()
{
InitializeComponent();
} private void InitializeComponent()
{
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
// } public string StatusInfo
{
set
{
_StatusInfo = value;
ChangeStatusText();
}
get
{
return _StatusInfo;
}
} public void ChangeStatusText()
{
try
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(this.ChangeStatusText));
return;
} labStatus.Text = _StatusInfo;
}
catch (Exception e)
{
// 异常处理
}
}
}

主界面类:

public class frmMain : System.Windows.Forms.Form
{
public frmMain()
{
InitializeComponent(); Splash.Status = "状态:载入初始化模块";
System.Threading.Thread.Sleep(); Splash.Status = "状态:载入管理模块";
System.Threading.Thread.Sleep(); Splash.Status = "状态:载入打印模块";
System.Threading.Thread.Sleep(); Splash.Status = "状态:载入插件模块";
System.Threading.Thread.Sleep(); Splash.Status = "状态:连接数据库";
System.Threading.Thread.Sleep(); Splash.Close();
}
}

[转]WinForm下Splash(启动画面)制作的更多相关文章

  1. C# WinForm程序添加启动画面

    如果程序在装载时需要进行较长时间的处理,最好使用启动画面,一方面美化程序,一方面可以不使用户面对着一片空白的程序界面. 我手头上一个小项目主界面启动时需要检查用户文件及运行环境是否有效,需要一段时间处 ...

  2. Delphi开发 Android 程序启动画面简单完美解决方案

    原文在这里 还是这个方法好用,简单!加上牧马人做的自动生成工具,更是简单. 以下为原文,向波哥敬礼! 前面和音儿一起研究 Android 下启动画面的问题,虽然问题得到了解决,但是,总是感觉太麻烦,主 ...

  3. 用VC制作应用程序启动画面

    摘 要:本文提供了四种启动画面制作方法. 使用启动画面一是可以减少等待程序加载过程中的枯燥感(尤其是一些大型程序):二是 可以用来显示软件名称和版权等提示信息.怎样使用VC++制作应用程序的启动画面呢 ...

  4. 从零开始学Xamarin.Forms(三) Android 制作启动画面

    原文:从零开始学Xamarin.Forms(三) Android 制作启动画面     Xamarin.Forms 在启动的时候相当慢,必须添加一个启动界面,步骤如下: 1.将启动画面的图片命名为:s ...

  5. Xamarin.Forms (Android制作启动画面)

    http://blog.csdn.net/zapzqc/article/details/38496117     Xamarin.Forms 在启动的时候相当慢,必须添加一个启动界面,步骤如下: 1. ...

  6. 【VC编程技巧】窗口☞3.5对单文档或者多文档程序制作启动画面

    (一)概要: 文章描写叙述了如何通过Visual C++ 2012或者Visual C++ .NET,为单文档或者多文档程序制作启动画面.在Microsoft Visual Studio 6.0中对于 ...

  7. xcode6+ios8 横屏下启动画面不显示问题修改

    本文转载自汉果博客 » xcode6+ios8 横屏下启动画面不显示问题修改 最近我做游戏 发现xcode6+ios8 横屏下启动画面不显示   显示黑屏 . 设置横屏后 设置catalog 添加使用 ...

  8. apple-touch-startup-image 制作iphone web应用程序的启动画面

    为ipad制作web应用程序的启动画面时发现个问题,只能显示竖屏图,横屏图出不来,如下: 首先页面头部里要加入(这个是APP启动画面图片,如果不设置,启动画面就是白屏,图片像素就是手机全屏的像素) & ...

  9. c#制作简单启动画面的方法

    本文实例讲述了c#制作简单启动画面的方法.分享给大家供大家参考.具体分析如下: 启动画面是程序启动加载组件时一个让用户稍微耐心等待的提示框.一个好的软件在有启动等待需求时必定做一个启动画面.启动画面可 ...

随机推荐

  1. linux模式切换,进程切换

    内核态和用户态的切换: 用户态到内核态的转换:1.进行系统调用,2.异步中断,3.外部硬件中断 检查特权级别的变化:当异常发生在用户态,而异常处理函数则必须运行在内核态,则此时必须调用内核态的堆栈(系 ...

  2. C++基础学习9:构造函数和析构函数

    1.  构造函数用来对类对象进行初始化,它完成对内存空间的申请.赋初值等工作.  2.  析构函数主要是用来做清理工作的. 补充:函数名或变量名前面有"::"但是没有类名,说明这是 ...

  3. CF959E Mahmoud and Ehab and the xor-MST 思维

    Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem t ...

  4. list与str互转

    import stringstr = 'abcde' list = list(str)list['a', 'b', 'c', 'd', 'e']str'abcde'str_convert = ''.j ...

  5. POJ1057 FILE MAPPING

    题目来源:http://poj.org/problem?id=1057 题目大意:计算机的用户通常希望能够看到计算机存储的文件的层次结构的图形化表示.Microsoft Windows的 " ...

  6. POJ3074 Sudoku 剪枝深(神?)搜

    emm...挺秀的...挺神的? 每行,每列,每宫用一个二进制数表示选或没选的状态,刚开始设没选为1,然后更改状态的时候异或一下就好了: 这样可以通过lowbit取出每一个没有选过的数:(妙啊? 关于 ...

  7. POJ 3734 Blocks(矩阵快速幂+矩阵递推式)

    题意:个n个方块涂色, 只能涂红黄蓝绿四种颜色,求最终红色和绿色都为偶数的方案数. 该题我们可以想到一个递推式 .   设a[i]表示到第i个方块为止红绿是偶数的方案数, b[i]为红绿恰有一个是偶数 ...

  8. hive distcp数据同步

    -- 同步HDFS数据(shell执行) hadoop distcp \ -Dmapred.job.queue.name=queue_name \ -update \ -skipcrccheck hd ...

  9. Fiddler相关配置

    1.General 2.HTTPS: 3.Connections 4.Gateway 5.appearance 6.Scripting url过滤: REGEX:\.(js|css|png|gif|h ...

  10. Tomcat在处理GET和POST请求时产生的乱码问题

    最近一直在做关于Servlet的事情,常常出现乱码,很是烦人,处理乱码的方法有时候有效,有时候没有效果,今天抽个时间小结一下,以防以后再出现这种问题. 一般的处理乱码的方式都是用: request.s ...