概要
スプラッシュウィンドウを表示するには、スプラッシュウィンドウ用のフォームを作成して、
アプリケーション起動時にフォームを表示することで実現できる。
サンプルコード
スプラッシュウィンドウ画面のオプションを下記のように設定する。
・StartPositionプロパティ - CenterScreen
・FormBorderStyleプロパティ - None
<syntaxhighlight lang="c#"> // Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Threading; namespace SplashWindow { static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // スプラッシュフォームを表示 FormSplash fs = new FormSplash(); fs.Show(); fs.Refresh(); // 時間のかかる処理を記述する(Sleepメソッドで代用) Thread.Sleep(3000); // スプラッシュウィンドウを閉じる fs.Close(); // メインフォームを表示 Application.Run(new FormMain()); } } } </source>
<syntaxhighlight lang="c#"> // FormMain.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace SplashWindow { public partial class FormMain : Form { public FormMain() { InitializeComponent(); } private void FormMain_Load(object sender, EventArgs e) { } } } </source>
<syntaxhighlight lang="c#"> // FormSplash.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace SplashWindow { public partial class FormSplash : Form { public FormSplash() { InitializeComponent(); } private void FormSplash_Paint(object sender, PaintEventArgs e) { Rectangle rect = new Rectangle(0,0, this.Width, this.Height); ControlPaint.DrawBorder3D(e.Graphics, rect, Border3DStyle.Raised); } } } </source>