アプリケーションの読み込み中に.NetのSplashScreenクラスを使用して動的メッセージを表示することはできますか?SplashScreenとカスタムメッセージ
何かが好きです。
モジュール1をロード...
モジュール2をロード...
など。
アプリケーションの読み込み中に.NetのSplashScreenクラスを使用して動的メッセージを表示することはできますか?SplashScreenとカスタムメッセージ
何かが好きです。
モジュール1をロード...
モジュール2をロード...
など。
いいえ、この機能を自分でコーディングする必要があります。組み込みのスプラッシュ画面には、静止画しか表示されません。
「System.Theading」を使用してこれを行うことができます。次のコードでは、別のスレッドで "スプラッシュ画面"を起動します。アプリケーション(MainForm()の下の私の例では)がロードまたは初期化されています。まず、あなたの "main()"メソッド(program.csファイルの名前を変更していない限り)にスプラッシュ画面を表示する必要があります。これは、起動時にユーザーを表示したいWinFormまたはWPFフォームになります。あなたは、次のようなものが必要あなたのスプラッシュ画面のコードで
[STAThread]
static void Main()
{
// Splash screen, which is terminated in MainForm.
SplashForm.ShowSplash();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Run UserCost.
Application.Run(new MainForm());
}
を::
public partial class SplashForm : Form
{
// Thredding.
private static Thread _splashThread;
private static SplashForm _splashForm;
public SplashForm()
{
InitializeComponent();
}
// Show the Splash Screen (Loading...)
public static void ShowSplash()
{
if (_splashThread == null)
{
// show the form in a new thread
_splashThread = new Thread(new ThreadStart(DoShowSplash));
_splashThread.IsBackground = true;
_splashThread.Start();
}
}
// Called by the thread
private static void DoShowSplash()
{
if (_splashForm == null)
_splashForm = new SplashForm();
// create a new message pump on this thread (started from ShowSplash)
Application.Run(_splashForm);
}
// Close the splash (Loading...) screen
public static void CloseSplash()
{
// Need to call on the thread that launched this splash
if (_splashForm.InvokeRequired)
_splashForm.Invoke(new MethodInvoker(CloseSplash));
else
Application.ExitThread();
}
}
これは、あなたがして進行させる別のバックグラウンドスレッドでスプラッシュフォームを起動し、次のようにこれは)(メインから打ち上げですメインアプリケーションのレンダリングを同時に行います。読み込みに関するメッセージを表示するには、メインのUIスレッドから情報を引き出すか、純粋に美的な性質で作業する必要があります。終えると、アプリケーションで使用すると、デフォルトコンストラクタ内で、次を配置初期化されたとき、スプラッシュスクリーンを閉鎖するには(あなたがしたい場合、あなたは、コンストラクタをオーバーロードできます):
は上記のコードは、に、比較的簡単なはず続く。
こちらがお役に立てば幸いです。