It may be a little late to answer, but I would like to share my path. I found a simple way with threads in the main program for a winform application.
Suppose you have a splashscreen of your form with animation and your main, which has all of your application code.
[STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Thread mythread; mythread = new Thread(new ThreadStart(ThreadLoop)); mythread.Start(); Application.Run(new MainForm(mythread)); } public static void ThreadLoop() { Application.Run(new SplashScreenForm()); }
In your main form in the constructor:
public MainForm(Thread splashscreenthread) { InitializeComponent();
Thus, the splash screen will only last for loading the main form.
The shape of your screen should have its own way of animating / displaying information. In my project, my splash screen launches a new stream, and every x milliseconds it changes the main image to another, which is a slightly different transmission, giving the illusion of rotation.
example of my splash screen:
int status = 0; private bool IsRunning = false; public Form1() { InitializeComponent(); StartAnimation(); } public void StartAnimation() { backgroundWorker1.WorkerReportsProgress = false; backgroundWorker1.WorkerSupportsCancellation = true; IsRunning = true; backgroundWorker1.RunWorkerAsync(); } public void StopAnimation() { backgroundWorker1.CancelAsync(); } delegate void UpdatingThreadAnimation(); public void UpdateAnimationFromThread() { try { if (label1.InvokeRequired == false) { UpdateAnimation(); } else { UpdatingThreadAnimation d = new UpdatingThreadAnimation(UpdateAnimationFromThread); this.Invoke(d, new object[] { }); } } catch(Exception e) { } } private void UpdateAnimation() { if(status ==0) {
Hope this helps some people. Sorry if I made some mistakes. English is not my first language.
Ornithorix Dec 03 '18 at 15:30 2018-12-03 15:30
source share