You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/labs/CameraCard/CameraCard/ProgressForm.cs

48 lines
1.3 KiB

using System;
using System.Windows.Forms;
namespace CameraCard
{
public partial class ProgressForm : Form
{
private readonly Action _closed;
public ProgressForm(string title, string status, int min, int max, int width = 0, Action action = null, bool control = true)
{
InitializeComponent();
this.Width = width == 0 ? this.Width : width;
this.Text = title;
this.status.Text = status;
this.progressBar.Minimum = min;
this.progressBar.Maximum = max;
this._closed = action;
this.ControlBox = control;
this.FormClosed += ProgressForm_FormClosed;
}
private void ProgressForm_FormClosed(object sender, FormClosedEventArgs e)
{
this._closed?.Invoke();
}
public void SetProgress(string label, int progress)
{
if (this.IsHandleCreated)
{
this.Invoke(new Action(() =>
{
this.status.Text = label;
this.progressBar.Value = progress;
}));
}
}
public void CloseProgress()
{
this.Invoke(new Action(() =>
{
this.Close();
}));
}
}
}