public static void CloseDialog() { if (dialog != null) { dialog.Close(); dialog = null; } }
public static String ShowInputDialog(Form parent, string title) { dialog = new PasswordInputDialog(); dialog.Text = title; if (dialog.ShowDialog(parent) == DialogResult.OK) { return(dialog.txtInput.Text); } return(""); }
private void CountDownWindow_FormClosing(object sender, FormClosingEventArgs e) { if (!task.IsTaskRunning()) { return; } bool isAborted = false; DialogResult rs = MessageBox.Show(this, "Abort shutdown task?", "Abort Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (rs == DialogResult.Yes) { if (task.IsTaskProtected()) { MessageBox.Show(this, "This task is protected", "Note", MessageBoxButtons.OK, MessageBoxIcon.Information); do { //display window for user to input password string userEntr = PasswordInputDialog.ShowInputDialog(this, "Enter your password"); isAborted = task.Abort(userEntr); } while (MessageBox.Show(this, "Invalid Password", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry); } else { try { isAborted = task.Abort(); } catch (AbortFailedException arg) { MessageBox.Show(this, "Failed to abort task, task is protected", "Note", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } //countdown window only closes if the task was aborted. e.Cancel = !isAborted; }