我想知道如何在C#中制作SplashScreen。我环顾了StackOverflow,但没有发现任何有用的东西,你能帮帮我吗?我已经有1个表格填充了东西,我只需要一些简单的说明如何:
我不需要动画闪屏 提前致谢!
请询问您是否需要我的任何代码示例:)
答案 0 :(得分:3)
这是一个启动画面的例子 - 我在我的一个项目中使用过 - 使用多线程:
namespace WindowsForm1
{
public enum SplashTypeOfMessage
{ Success,
Warning,
Error
}
public partial class SplashForm : Form
{
static SplashForm _splashForm = null;
static Thread _splashThread = null;
public static object locker = new object();
public static bool WaitPlease = true;
private SplashForm()
{
InitializeComponent();
lblLoading.Text = "Please wait Loading";
}
public static void ShowSplashScreen()
{
if (_splashForm != null)
return;
_splashThread = new Thread(new ThreadStart(SplashForm.ShowSplash));
_splashThread.IsBackground = true;
_splashThread.SetApartmentState(ApartmentState.STA) ;
_splashThread.Start();
}
public static void ShowSplash()
{
if (_splashForm==null)
{
_splashForm = new SplashForm();
_splashForm.blueLoaderBar1.StartAnimation();
}
_splashForm.TopMost = true;
_splashForm.Show();
lock (SplashForm.locker)
{
WaitPlease = false;
}
Application.Run(_splashForm);
}
delegate void CloseSplashHandler(SplashTypeOfMessage typeOfMessage, string message,bool itWasRinvoked);
public static void CloseSplash(SplashTypeOfMessage typeOfMessage,string message,bool itWasrinvoked)
{
CloseSplashHandler closeSpalshHandler = new CloseSplashHandler(CloseSplash);
bool launched=false;
while (!launched && !itWasrinvoked)
{
lock (SplashForm.locker)
{
if (!SplashForm.WaitPlease)
{
launched = true;
}
}
}
if (_splashForm!=null && _splashThread!=null )
{
if (_splashForm.InvokeRequired)
{
_splashForm.Invoke(closeSpalshHandler,new object[] {typeOfMessage,message,true});
}
else
{
switch (typeOfMessage)
{
case SplashTypeOfMessage.Warning:
break;
case SplashTypeOfMessage.Error:
MessageBox.Show("Error");
break;
default:
break;
}
_splashForm.Close();
_splashThread = null;
}
}
}
}
}
以下是如何调用它:
SplashForm.ShowSplashScreen();
这是关闭启动画面的方法:
SplashForm.CloseSplash(typeOfMessage ,string.Empty,false);