2020-04-18 22:24:48 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace VoxCharger
|
|
|
|
|
{
|
|
|
|
|
public partial class LoadingForm : Form
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
private Action<LoadingForm> _action;
|
|
|
|
|
private bool _completed = false;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
|
|
|
|
|
public LoadingForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnLoadingForm(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnLoadingFormShown(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
this._action(this);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
public void SetAction(Action<LoadingForm> action)
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
this._action = action;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetStatus(string text)
|
|
|
|
|
{
|
|
|
|
|
if (StatusLabel.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
StatusLabel.Invoke(new Action(() => SetStatus(text)));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusLabel.Text = text;
|
|
|
|
|
StatusLabel.Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetProgress(float percentage)
|
|
|
|
|
{
|
|
|
|
|
if (ProgressBar.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
ProgressBar.Invoke(new Action<float>(SetProgress), percentage);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
percentage = percentage > 100f ? 100f : percentage < 0f ? 0f : percentage;
|
|
|
|
|
ProgressBar.Value = (int)percentage;
|
|
|
|
|
ProgressBar.Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Complete()
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
_completed = true;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
if (InvokeRequired)
|
|
|
|
|
Invoke(new Action(Close));
|
|
|
|
|
else
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnLoadingFormFormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
e.Cancel = !_completed;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|