public partial class ProgressDialog : Form
{
public delegate void CancelEventHandler();
public event CancelEventHandler CancelButtonClick;
public ProgressDialog()
{
InitializeComponent();
}
private void buttonCancel_Click(object sender, EventArgs e)
{
if (CancelButtonClick != null)
{
CancelButtonClick();
}
this.Close();
}
public void UpdateProgressMessage(string progressMessage)
{
lblProgressMessage.Text = progressMessage;
}
}
private delegate void ShowProgressDialog_Delegate(string progressDialogCaption, ProgressDialog.CancelEventHandler progressCancelled, bool reportProgress);
private void ShowProgressDialog(string progressDialogCaption, ProgressDialog.CancelEventHandler progressCancelled, bool reportProgress)
{
if (InvokeRequired)
{
BeginInvoke(new ShowProgressDialog_Delegate(ShowProgressDialog), new object[] { progressDialogCaption, progressCancelled, reportProgress });
}
else
{
try
{
progressDialog = new ProgressDialog();
progressDialog.Owner = base.FindForm();
progressDialog.CancelButtonClick += progressCancelled;
progressDialog.Text = progressDialogCaption;
if (reportProgress)
{
progressDialog.progressBar.Style = ProgressBarStyle.Continuous;
}
progressDialog.Show();
}
catch { }
}
}
///
/// Close the Progress Dialog
///
private delegate void StopProgressDialog_Delegate();
private void StopProgressDialog()
{
if (InvokeRequired)
{
BeginInvoke(new StopProgressDialog_Delegate(StopProgressDialog), new object[] { });
}
else
{
if (!progressDialog.IsDisposed)
{
progressDialog.Close();
}
}
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
StopProgressDialog();
if (e.Cancelled == true)
{
MessageBox.Show("Installation Cancelled!");
}
else if (e.Error != null)
{
MessageBox.Show("Installation Error: " + e.Error.Message);
}
else
{
MessageBox.Show("Installed successfully!");
}
}
void progress_CancelButtonClick()
{
TestsOptionChanged_Click(null, null);
abortFlag = true;
}
No comments:
Post a Comment