This repository has been archived on 2023-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
PainterlyUNO/Matrix App/forms/SplashScreen.cs

64 lines
1.8 KiB
C#
Raw Permalink Normal View History

2021-06-09 19:19:30 +00:00
using System.Drawing;
using System.Threading;
2021-06-09 17:53:36 +00:00
using System.Windows.Forms;
namespace Matrix_App
{
public class SplashScreen : Form
{
//Delegate for cross thread call to close
private delegate void CloseDelegate();
//The type of form to be displayed as the splash screen.
private static SplashScreen? _splashForm;
private SplashScreen()
{
FormBorderStyle = FormBorderStyle.None;
Controls.Add(new Label()
{
2021-06-09 19:19:30 +00:00
Image = Properties.Resources.Pfüsikuh,
Size = new Size(Properties.Resources.Pfüsikuh.Width, Properties.Resources.Pfüsikuh.Height)
2021-06-09 17:53:36 +00:00
});
2021-06-09 19:19:30 +00:00
Size = new Size(Properties.Resources.Pfüsikuh.Width, Properties.Resources.Pfüsikuh.Height);
StartPosition = FormStartPosition.CenterScreen;
2021-06-09 17:53:36 +00:00
}
public static void ShowSplashScreen()
{
// Make sure it is only launched once.
if (_splashForm != null)
return;
_splashForm = new SplashScreen();
Thread thread = new Thread(ShowForm)
{
IsBackground = true, Name = "Splash screen management thread"
};
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
private static void ShowForm()
{
if (_splashForm != null) Application.Run(_splashForm);
}
public static void CloseForm()
{
_splashForm?.Invoke(new CloseDelegate(CloseFormInternal));
}
private static void CloseFormInternal()
{
if (_splashForm != null)
{
_splashForm.Close();
_splashForm = null;
}
}
}
}