逛逛sourceforge,有时候会有不错的东西能淘到,就比如这个开机画面的Form就不错,(在一个report的项目里,出处又是别的地方。。。)。要用的话,把代码拷过来,在form里改改背景图片,就可以了,对了还得加个timer。这个类用静态方法包装了一个线程,在开机的时候单独执行,渐入渐出也很好控制,尤为好的是在splash的时候就可以向里面实时的写进度条了,而不是先设置好了格子。。。开始的时候用这个方法就可以激活了:
SplashScreen.ShowSplashScreen();
写信息是用这个方法,不会阻塞怎么写都行,嘿嘿:
SplashScreen.SetStatus(moduleName);
不过,为了避免一开始程序的时候执行splash以及主线程会抢,还是用个OnAppIdle在进程空闲的时候开始执行主线程为好。
static void Main()
{
System.Windows.Forms.Application.Idle += new EventHandler(OnAppIdle)
....................................
OnAppIdle里这样写:当然为了达到这点,得把进程的context提出来
private static System.Windows.Forms.ApplicationContext context;
private static MainForm mForm = new MainForm();
private static void OnAppIdle(object sender, EventArgs e)
{
if(context.MainForm == null)
{
// first we remove the eventhandler
System.Windows.Forms.Application.Idle -= new EventHandler(OnAppIdle);
//调用SplashScreen.ShowSplashScreen();写点东西
...................................
// now we set the main form for the context...
context.MainForm = mForm;
// ...show it...调用主form
context.MainForm.Show();
................................................................
接下来就是splash的代码了:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
using Microsoft.Win32;
namespace SplashDemo
{
/// <summary>
/// Splash screen implemented by Tom Clement, see the CodeProject
/// http://www.codeproject.com/csharp/PrettyGoodSplashScreen.asp
/// </summary>
public class SplashScreen : System.Windows.Forms.Form
{
// Threading
static SplashScreen ms_frmSplash = null;
static Thread ms_oThread = null;
// Fade in and out.
private double m_dblOpacityIncrement = .05;
private double m_dblOpacityDecrement = .08;
private const int TIMER_INTERVAL = 50;
// Status and progress bar
static string ms_sStatus;
private double m_dblCompletionFraction = 0;
private Rectangle m_rProgress;
// Progress smoothing
private double m_dblLastCompletionFraction = 0.0;
private double m_dblPBIncrementPerTimerInterval = .015;
// Self-calibration support
private bool m_bFirstLaunch = false;
private DateTime m_dtStart;
private bool m_bDTSet = false;
private int m_iIndex = 1;
private int m_iActualTicks = 0;
private ArrayList m_alPreviousCompletionFraction;
private ArrayList m_alActualTimes = new ArrayList();
private const string REG_KEY_INITIALIZATION = "Initialization";
private const string REGVALUE_PB_MILISECOND_INCREMENT = "Increment";
private const string REGVALUE_PB_PERCENTS = "Percents";
private System.Windows.Forms.Label lblStatus;
private System.Windows.Forms.Label lblTimeRemaining;
private System.Windows.Forms.Timer timer1;
private System.Window