C Sharpの応用 - スプラッシュウィンドウ
ナビゲーションに移動
検索に移動
概要
スプラッシュウィンドウを表示するには、スプラッシュウィンドウ用のフォームを作成して、 アプリケーション起動時にフォームを表示することで実現できる。
サンプルコード
スプラッシュウィンドウ画面のオプションを下記のように設定する。 StartPositionプロパティ - CenterScreen FormBorderStyle - None
// 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();
Thread.Sleep(3000);//時間のかかる処理
fs.Close();
Application.Run(new FormMain());
}
}
}
// 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)
{
}
}
}
// 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);
}
}
}