「C Sharpの応用 - スプラッシュウィンドウ」の版間の差分
提供: MochiuWiki : SUSE, EC, PCB
細 Wiki がページ「スプラッシュウィンドウを表示する(C Sharp)」を「C Sharpの応用 - スプラッシュウィンドウ」に、リダイレクトを残さずに移動しました |
細 文字列「<source」を「<syntaxhighlight」に置換 |
||
| 9行目: | 9行目: | ||
・FormBorderStyleプロパティ - None<br> | ・FormBorderStyleプロパティ - None<br> | ||
<br> | <br> | ||
< | <syntaxhighlight lang="c#"> | ||
// Program.cs | // Program.cs | ||
using System; | using System; | ||
| 45行目: | 45行目: | ||
</source> | </source> | ||
<br> | <br> | ||
< | <syntaxhighlight lang="c#"> | ||
// FormMain.cs | // FormMain.cs | ||
using System; | using System; | ||
| 73行目: | 73行目: | ||
</source> | </source> | ||
<br> | <br> | ||
< | <syntaxhighlight lang="c#"> | ||
// FormSplash.cs | // FormSplash.cs | ||
using System; | using System; | ||
2021年11月15日 (月) 02:21時点における版
概要
スプラッシュウィンドウを表示するには、スプラッシュウィンドウ用のフォームを作成して、
アプリケーション起動時にフォームを表示することで実現できる。
サンプルコード
スプラッシュウィンドウ画面のオプションを下記のように設定する。
・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>