You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
4.2 KiB
C#
148 lines
4.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Windows.Forms;
|
|
using System.Threading;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
|
|
namespace POSV
|
|
{
|
|
public partial class SplashScreen : Form
|
|
{
|
|
static SplashScreen ms_frmSplash = null;
|
|
static Thread ms_oThread = null;
|
|
|
|
private double m_dblOpacityIncrement = .05;
|
|
private double m_dblOpacityDecrement = .08;
|
|
private const int TIMER_INTERVAL = 50;
|
|
|
|
static string ms_sStatus;
|
|
private double m_dblCompletionFraction = 0;
|
|
|
|
private double m_dblLastCompletionFraction = 0.0;
|
|
|
|
private DateTime m_dtStart;
|
|
private bool m_bDTSet = false;
|
|
private int m_iIndex = 1;
|
|
private int m_iActualTicks = 0;
|
|
private ArrayList m_alPreviousCompletionFraction = null;
|
|
private ArrayList m_alActualTimes = new ArrayList();
|
|
|
|
|
|
public SplashScreen()
|
|
{
|
|
InitializeComponent();
|
|
|
|
var splash = @"images/splash.png";
|
|
if (File.Exists(splash))
|
|
{
|
|
this.mainPanel.BackgroundImageLayout = ImageLayout.Tile;
|
|
this.mainPanel.BackgroundImage = Image.FromFile(splash);
|
|
}
|
|
|
|
this.Opacity = .00;
|
|
timer.Interval = TIMER_INTERVAL;
|
|
timer.Start();
|
|
}
|
|
|
|
public static void ShowSplashScreen()
|
|
{
|
|
if (ms_frmSplash != null)
|
|
return;
|
|
ms_oThread = new Thread(new ThreadStart(SplashScreen.ShowForm));
|
|
ms_oThread.IsBackground = true;
|
|
ms_oThread.SetApartmentState(ApartmentState.STA);
|
|
ms_oThread.Start();
|
|
}
|
|
|
|
public static SplashScreen SplashForm
|
|
{
|
|
get
|
|
{
|
|
return ms_frmSplash;
|
|
}
|
|
}
|
|
|
|
private static void ShowForm()
|
|
{
|
|
ms_frmSplash = new SplashScreen();
|
|
ms_frmSplash.ShowDialog();
|
|
}
|
|
|
|
public static void CloseForm()
|
|
{
|
|
if (ms_frmSplash != null && ms_frmSplash.IsDisposed == false)
|
|
{
|
|
ms_frmSplash.m_dblOpacityIncrement = -ms_frmSplash.m_dblOpacityDecrement;
|
|
}
|
|
ms_oThread = null;
|
|
ms_frmSplash = null;
|
|
}
|
|
|
|
public static void SetStatus(string newStatus)
|
|
{
|
|
SetStatus(newStatus, true);
|
|
}
|
|
|
|
public static void SetStatus(string newStatus, bool setReference)
|
|
{
|
|
ms_sStatus = newStatus;
|
|
if (ms_frmSplash == null)
|
|
return;
|
|
if (setReference)
|
|
ms_frmSplash.SetReferenceInternal();
|
|
}
|
|
|
|
public static void SetReferencePoint()
|
|
{
|
|
if (ms_frmSplash == null)
|
|
return;
|
|
ms_frmSplash.SetReferenceInternal();
|
|
|
|
}
|
|
|
|
private void SetReferenceInternal()
|
|
{
|
|
if (m_bDTSet == false)
|
|
{
|
|
m_bDTSet = true;
|
|
m_dtStart = DateTime.Now;
|
|
}
|
|
double dblMilliseconds = ElapsedMilliSeconds();
|
|
m_alActualTimes.Add(dblMilliseconds);
|
|
m_dblLastCompletionFraction = m_dblCompletionFraction;
|
|
if (m_alPreviousCompletionFraction != null && m_iIndex < m_alPreviousCompletionFraction.Count)
|
|
m_dblCompletionFraction = (double)m_alPreviousCompletionFraction[m_iIndex++];
|
|
else
|
|
m_dblCompletionFraction = (m_iIndex > 0) ? 1 : 0;
|
|
}
|
|
|
|
|
|
private double ElapsedMilliSeconds()
|
|
{
|
|
TimeSpan ts = DateTime.Now - m_dtStart;
|
|
return ts.TotalMilliseconds;
|
|
}
|
|
|
|
private void timer_Tick(object sender, System.EventArgs e)
|
|
{
|
|
lblStatus.Text = ms_sStatus;
|
|
|
|
if (m_dblOpacityIncrement > 0)
|
|
{
|
|
m_iActualTicks++;
|
|
if (this.Opacity < 1)
|
|
this.Opacity += m_dblOpacityIncrement;
|
|
}
|
|
else
|
|
{
|
|
if (this.Opacity > 0)
|
|
this.Opacity += m_dblOpacityIncrement;
|
|
else
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |