http://blogs.wankuma.com/rti/archive/2007/03/28/69289.aspx
http://blogs.wankuma.com/rti/archive/2007/01/10/55358.aspx
http://blogs.wankuma.com/shannon/archive/2007/01/11/55582.aspx
以前わんくまでもスプラッシュウインドウが話題になっていたけど、解決したのか解決していないのか分からないうちに終わってしまった(?)ようなので、自分でもちょっと考えてみました。
ApplicationContext を使って上から時系列的に書いただけなんですけどどうでしょうか?(コード直打ちなのでミスがあるかも(^^))
MyApplicationContext.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace YO
{
class MyApplicationContext<MyForm> : ApplicationContext
where MyForm : Form, new()
{
private SplashWindow _splash = null;
private MyForm _myForm = null;
public MyApplicationContext() : base()
{
try
{
this._splash = new SplashWindow();
this.MainForm = this._splash;
this._splash.Shown += new EventHandler(splash_Shown);
}
catch (Exception)
{
if (this._splash != null)
{
this._splash.Dispose();
}
base.ExitThread();
}
}
void splash_Shown(object sender, EventArgs e)
{
try
{
this._myForm = new MyForm();
this._myForm.Shown += new EventHandler(myForm_Shown);
this._myForm.FormClosed += new FormClosedEventHandler(myForm_FormClosed);
this._myForm.Show();
}
catch (Exception)
{
if (this._splash != null)
{
this._splash.Close();
}
}
}
void myForm_Shown(object sender, EventArgs e)
{
if (this._splash != null)
{
this._splash.Hide();
}
}
void myForm_FormClosed(object sender, FormClosedEventArgs e)
{
if (this._splash != null)
{
this._splash.Close();
}
}
}
}
program.cs
[STAThread]
static void Main()
{
MyApplicationContext<OriginalForm> appContext = new MyApplicationContext<OriginalForm>();
Application.Run(appContext);
}
本来 Splash はメインのフォームが表示された後に破棄してしまいたいんですが ApplicationContext の MainForm にセットしてしまっているので仕方なく Hide してしまっています。これさえ何とかなればなぁ~…。