1
0
mirror of https://github.com/SirusDoma/VoxCharger.git synced 2024-11-27 17:00:51 +01:00
VoxCharger/Sources/Forms/LoadingForm.cs

70 lines
1.6 KiB
C#
Raw Permalink Normal View History

2020-04-18 22:24:48 +02:00
using System;
using System.Windows.Forms;
namespace VoxCharger
{
public partial class LoadingForm : Form
{
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)
{
this._action(this);
2020-04-18 22:24:48 +02:00
}
public void SetAction(Action<LoadingForm> action)
2020-04-18 22:24:48 +02: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()
{
_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)
{
e.Cancel = !_completed;
2020-04-18 22:24:48 +02:00
}
}
}