private bool Confirm(string TaskName) { if (isVista) { TaskDialog td = new TaskDialog(); TaskDialogStandardButtons button = TaskDialogStandardButtons.Yes; button |= TaskDialogStandardButtons.No; td.Icon = TaskDialogStandardIcon.Information; td.StandardButtons = button; td.InstructionText = TaskName; td.Caption = TaskName; td.Text = Properties.Resources.Str_Confirm; TaskDialogResult res = td.Show(); if (res.ToString() != "Yes") { return(false); } } else { DialogResult result = MessageBox.Show( Properties.Resources.Str_Confirm, Properties.Resources.Confirm, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result != DialogResult.Yes) { return(false); } } return(true); }
private static MessageBoxButtons GetMessageBoxButtons(TaskDialogStandardButtons buttons) { if ((buttons & TaskDialogStandardButtons.Ok) == TaskDialogStandardButtons.Ok && (buttons & TaskDialogStandardButtons.Cancel) == TaskDialogStandardButtons.Cancel) { return(MessageBoxButtons.OKCancel); } else if ((buttons & TaskDialogStandardButtons.Retry) == TaskDialogStandardButtons.Retry && (buttons & TaskDialogStandardButtons.Cancel) == TaskDialogStandardButtons.Cancel) { return(MessageBoxButtons.RetryCancel); } else if ((buttons & TaskDialogStandardButtons.Yes) == TaskDialogStandardButtons.Yes && (buttons & TaskDialogStandardButtons.No) == TaskDialogStandardButtons.No) { return(MessageBoxButtons.YesNo); } else if ((buttons & TaskDialogStandardButtons.Yes) == TaskDialogStandardButtons.Yes && (buttons & TaskDialogStandardButtons.No) == TaskDialogStandardButtons.No && (buttons & TaskDialogStandardButtons.Cancel) == TaskDialogStandardButtons.Cancel) { return(MessageBoxButtons.YesNoCancel); } return(MessageBoxButtons.OK); }
/// <summary> /// Show generic user dialog with yes to all option. /// </summary> /// <param name="windowTitleText">Title that appears in the title bar of the popup window.</param> /// <param name="title">Title that appears inside the popup window.</param> /// <param name="message">Detailed messages appearing in the popup window.</param> /// <param name="itemsCount">Number of items for which the operation will be repeated.</param> /// <param name="repeatForAll">Indicates whether a user wants to apply the action to all items.</param> /// <param name="icon"></param> /// <returns><code>TaskDialogResult</code> object indicating which option user selected.</returns> public static TaskDialogResult ShowYesNoDialog(string windowTitleText, string title, string message, int itemsCount, out bool repeatForAll, TaskDialogStandardIcon icon = TaskDialogStandardIcon.Information) { if (TaskDialog.IsPlatformSupported) { var taskdlg = new TaskDialog(); const TaskDialogStandardButtons button = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No | TaskDialogStandardButtons.Cancel; taskdlg.Icon = icon; taskdlg.Caption = windowTitleText; taskdlg.InstructionText = title; taskdlg.Text = message; taskdlg.StandardButtons = button; if (itemsCount > 1) { taskdlg.FooterCheckBoxChecked = false; taskdlg.FooterCheckBoxText = string.Format("Do this for remaining {0} items.", itemsCount - 1); } var result = taskdlg.Show(); repeatForAll = taskdlg.FooterCheckBoxChecked.GetValueOrDefault(false); return(result); } else { repeatForAll = false; var result = MessageBox.Show(message, windowTitleText, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); return(GetTaskDialogResult(result)); } }
private void TaskControlActionDelete() { TaskDialogResult result; ScanTask selectedTask = typedTaskList.SelectedObject; logger.Trace("Displaying task deletion confirmation dialog"); using (var dialog = new TaskDialog()) { TaskDialogStandardButtons button = TaskDialogStandardButtons.None; button |= TaskDialogStandardButtons.Yes; button |= TaskDialogStandardButtons.No; dialog.StandardButtons = button; dialog.StartupLocation = TaskDialogStartupLocation.CenterOwner; dialog.OwnerWindowHandle = this.Handle; dialog.Icon = TaskDialogStandardIcon.Information; const string Title = "Delete Task"; string instruction = "The scan task '" + listViewTasks.SelectedItems[0].Text + "' is about to be deleted"; const string Content = "Do you want to continue?"; dialog.InstructionText = instruction; dialog.Caption = Title; dialog.Text = Content; result = dialog.Show(); } if (result == TaskDialogResult.Yes) { try { logger.Debug("Removing task {0}", selectedTask.Name); ScanTaskManager.RemoveTask(selectedTask); LoadTaskList(); } catch (Exception ex) { MessageBox.Show( string.Format( "'{0}' could not be deleted.{1}Detail:{2}", selectedTask.Name, Environment.NewLine, ex.Message), "Task Manager", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } else { logger.Trace("Removal of task '{0}' cancelled by user", selectedTask.Name); } }
private void Done(string TaskName) { TaskDialog td = new TaskDialog(); TaskDialogStandardButtons button = TaskDialogStandardButtons.Ok; td.Icon = TaskDialogStandardIcon.Information; td.StandardButtons = button; td.InstructionText = TaskName; td.Caption = TaskName; td.Text = Properties.Resources.Complete; TaskDialogResult res = td.Show(); }
private void toolStripButtonDelete_Click(object sender, EventArgs e) { TaskDialogResult res; using (var td = new TaskDialog()) { TaskDialogStandardButtons button = TaskDialogStandardButtons.None; button |= TaskDialogStandardButtons.Yes; button |= TaskDialogStandardButtons.No; td.StandardButtons = button; td.StartupLocation = TaskDialogStartupLocation.CenterOwner; td.OwnerWindowHandle = this.Handle; td.Icon = TaskDialogStandardIcon.Information; td.Caption = "Delete Selected Report?"; td.InstructionText = "The selected report will be permanently deleted."; td.Text = "Do you want to continue?"; res = td.Show(); } if (res == TaskDialogResult.Yes) { try { logger.Debug("Removing report: {0}", typedReportView.SelectedObject.Name); ReportManager.RemoveReport(typedReportView.SelectedObject); } catch (Exception deleteException) { logger.Error( deleteException, string.Format("Unable to delete '{0}'", typedReportView.SelectedObject.Name)); MessageBox.Show( string.Format( "Unable to delete report '{0}'.{1}Detail:{2}", typedReportView.SelectedObject.Name, Environment.NewLine, deleteException.Message), WindowTitleBase, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } finally { LoadReportsList(); } } }
public static TaskDialog CreateMessageDialog(string caption, string message, TaskDialogStandardButtons buttons, TaskDialogStandardIcon icon, IntPtr owner) { var td = new TaskDialog { Caption = MainCaption, InstructionText = caption, Text = message, StandardButtons = buttons, OwnerWindowHandle = owner }; td.SetIconAndSound(icon); return(td); }
// Gives event subscriber a chance to prevent // the dialog from closing, based on // the current state of the app and the button // used to commit. Note that we don't // have full access at this stage to // the full dialog state. internal int RaiseClosingEvent(int id) { EventHandler <TaskDialogClosingEventArgs> handler = Closing; if (handler != null) { TaskDialogButtonBase customButton = null; TaskDialogClosingEventArgs e = new TaskDialogClosingEventArgs(); // Try to identify the button - is it a standard one? TaskDialogStandardButtons buttonClicked = MapButtonIdToStandardButton(id); // If not, it had better be a custom button... if (buttonClicked == TaskDialogStandardButtons.None) { customButton = GetButtonForId(id); // ... or we have a problem. if (customButton == null) { throw new InvalidOperationException("Bad button ID in closing event."); } e.CustomButton = customButton.Name; e.TaskDialogResult = TaskDialogResult.CustomButtonClicked; } else { e.TaskDialogResult = (TaskDialogResult)buttonClicked; } // Raise the event and determine how to proceed. handler(this, e); if (e.Cancel) { return((int)HRESULT.S_FALSE); } } // It's okay to let the dialog close. return((int)HRESULT.S_OK); }
public void Error(Exception e, string TaskName) { // Error dialog TaskDialog tdError = new TaskDialog(); TaskDialogStandardButtons button = TaskDialogStandardButtons.Ok; tdError.StandardButtons = button; tdError.DetailsExpanded = false; tdError.Cancelable = true; tdError.Icon = TaskDialogStandardIcon.Error; tdError.Caption = TaskName; tdError.InstructionText = Properties.Resources.ErrorMsg; tdError.DetailsExpandedText = e.ToString(); tdError.ExpansionMode = TaskDialogExpandedDetailsLocation.ExpandFooter; TaskDialogResult res = tdError.Show(); }
private void toolStripButtonDelete_Click(object sender, EventArgs e) { TaskDialogResult res; using (var td = new TaskDialog()) { TaskDialogStandardButtons button = TaskDialogStandardButtons.None; button |= TaskDialogStandardButtons.Yes; button |= TaskDialogStandardButtons.No; td.StartupLocation = TaskDialogStartupLocation.CenterOwner; td.OwnerWindowHandle = this.Handle; td.Icon = TaskDialogStandardIcon.Information; const string Title = "Delete File"; string instruction = "The file '" + fileItem.Name + "' will be permanently deleted"; const string Content = "Do you want to continue?"; td.StandardButtons = button; td.InstructionText = instruction; td.Caption = Title; td.Text = Content; res = td.Show(); } if (res == TaskDialogResult.Yes) { try { File.Delete(fileItem.AbsolutePath); } catch (Exception deleteFileException) { MessageBox.Show("The file could not be deleted." + Environment.NewLine + "Detail: " + deleteFileException.Message, "EduSweep 2", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } finally { Close(); } } }
public static TaskDialog Message(string caption, string message, TaskDialogStandardButtons buttons = TaskDialogStandardButtons.Ok, TaskDialogStandardIcon icon = TaskDialogStandardIcon.None, IWin32Window owner = null) { var td = new TaskDialog { Icon = icon, Caption = MainCaption, InstructionText = caption, Text = message, StandardButtons = buttons, OwnerWindowHandle = owner?.Handle ?? IntPtr.Zero }; td.Opened += (sender, args) => { td.Icon = icon; switch (icon) { case TaskDialogStandardIcon.None: break; case TaskDialogStandardIcon.Warning: SystemSounds.Exclamation.Play(); break; case TaskDialogStandardIcon.Error: SystemSounds.Hand.Play(); break; case TaskDialogStandardIcon.Information: SystemSounds.Asterisk.Play(); break; case TaskDialogStandardIcon.Shield: break; default: throw new ArgumentOutOfRangeException(nameof(icon), icon, null); } }; return(td); }
// Analyzes the final state of the NativeTaskDialog instance and creates the // final TaskDialogResult that will be returned from the public API private static TaskDialogResult ConstructDialogResult(NativeTaskDialog native) { Debug.Assert(native.ShowState == DialogShowState.Closed, "dialog result being constructed for unshown dialog."); TaskDialogResult result = TaskDialogResult.Cancel; TaskDialogStandardButtons standardButton = MapButtonIdToStandardButton(native.SelectedButtonId); // If returned ID isn't a standard button, let's fetch if (standardButton == TaskDialogStandardButtons.None) { result = TaskDialogResult.CustomButtonClicked; } else { result = (TaskDialogResult)standardButton; } return(result); }
/// <summary> /// Show a simple task dialog message box. /// </summary> /// <param name="element">The element used to determine the owner window.</param> /// <param name="caption">The message box caption.</param> /// <param name="instructionText">The instruction text in the message box.</param> /// <param name="text">The detailed text in the message box.</param> /// <param name="icon">The icon in the message box.</param> /// <param name="buttons">The buttons in the message box.</param> /// <returns>The dialog result user selected.</returns> public static TaskDialogResult ShowMessage(this FrameworkElement element, [Localizable(true)] string caption, [Localizable(true)] string instructionText, [Localizable(true)] string text, TaskDialogStandardIcon icon, TaskDialogStandardButtons buttons) { var dialog = new TaskDialog { Caption = caption, InstructionText = instructionText, Text = text, Icon = icon, StandardButtons = buttons, Cancelable = true, OwnerWindowHandle = Window.GetWindow(element).GetWindowHandle(), StartupLocation = TaskDialogStartupLocation.CenterOwner }; using (dialog) { return(dialog.Show()); } }
private void buttonClose_Click(object sender, EventArgs e) { if (modified) { TaskDialogResult res; using (var dialog = new TaskDialog()) { TaskDialogStandardButtons button = TaskDialogStandardButtons.None; button |= TaskDialogStandardButtons.Yes; button |= TaskDialogStandardButtons.No; dialog.StartupLocation = TaskDialogStartupLocation.CenterOwner; dialog.OwnerWindowHandle = this.Handle; dialog.Icon = TaskDialogStandardIcon.Warning; const string Title = "Signature Editor"; string instruction = "The current signature has unsaved changes which will be " + "discarded if this window is closed."; const string Content = "Close the editor and discard these changes?"; dialog.StandardButtons = button; dialog.InstructionText = instruction; dialog.Caption = Title; dialog.Text = Content; dialog.StartupLocation = TaskDialogStartupLocation.CenterOwner; dialog.OwnerWindowHandle = this.Handle; res = dialog.Show(); } if (res == TaskDialogResult.Yes) { Close(); } } else { Close(); } }
/// <summary> /// Show generic user dialog with yes to all option. /// </summary> /// <param name="windowTitleText">Title that appears in the title bar of the popup window.</param> /// <param name="title">Title that appears inside the popup window.</param> /// <param name="message">Detailed messages appearing in the popup window.</param> /// <param name="icon"></param> /// <returns><code>TaskDialogResult</code> object indicating which option user selected.</returns> public static TaskDialogResult ShowYesNoDialog(string windowTitleText, string title, string message, TaskDialogStandardIcon icon = TaskDialogStandardIcon.Information) { if (TaskDialog.IsPlatformSupported) { var taskdlg = new TaskDialog(); const TaskDialogStandardButtons button = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No | TaskDialogStandardButtons.Cancel; taskdlg.Icon = icon; taskdlg.Caption = windowTitleText; taskdlg.InstructionText = title; taskdlg.Text = message; taskdlg.StandardButtons = button; var result = taskdlg.Show(); return(result); } else { var result = MessageBox.Show(message, windowTitleText, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); return(GetTaskDialogResult(result)); } }
public static TaskDialogResult ShowMessage(string caption, string message, TaskDialogStandardButtons buttons) { return(CreateMessageDialog(caption, message, buttons, TaskDialogStandardIcon.None, IntPtr.Zero).Show()); }
public static TaskDialogResult CommonWarningDialog(string title, string main, string message, TaskDialogStandardButtons buttons = TaskDialogStandardButtons.Ok | TaskDialogStandardButtons.Cancel) { TaskDialog td = new TaskDialog(); td.Caption = title; td.InstructionText = main; td.Text = message; td.Icon = TaskDialogStandardIcon.Warning; td.Cancelable = false; td.StandardButtons = buttons; td.OwnerWindowHandle = ScreenParameters.GetWindowHandle(Common.GetCurrentWindow()); td.StartupLocation = TaskDialogStartupLocation.CenterOwner; td.Opened += Common.TaskDialog_Opened; return(td.Show()); }
private static DialogResult Show(Guid id, string title, string instruction, string message, TaskDialogStandardButtons buttons, TaskDialogStandardIcon icon, string details, int progressBarMaxValue, Action <int> tickEventHandler) { TaskDialogProgressBar progressBar = progressBarMaxValue < 0 ? null : new TaskDialogProgressBar(0, progressBarMaxValue, 0) { State = progressBarMaxValue == 0 ? TaskDialogProgressBarState.Marquee : TaskDialogProgressBarState.Normal }; APITaskDialog taskDialog = new APITaskDialog() { Caption = title, InstructionText = instruction, Text = message, Icon = icon, StandardButtons = buttons, Cancelable = true, ExpansionMode = TaskDialogExpandedDetailsLocation.ExpandFooter, DetailsExpanded = false, DetailsCollapsedLabel = "Show Details", DetailsExpandedLabel = "Hide Details", DetailsExpandedText = details, ProgressBar = progressBar, StartupLocation = TaskDialogStartupLocation.CenterOwner, OwnerWindowHandle = NativeMethods.GetActiveWindow() }; Action <object, TaskDialogTickEventArgs> internalTickEventHandler = null; if (tickEventHandler != null) { internalTickEventHandler = (sender, e) => tickEventHandler(e.Ticks); taskDialog.Tick += new EventHandler <TaskDialogTickEventArgs>(internalTickEventHandler); } if (id != Guid.Empty) { lock (_taskDialogs) _taskDialogs[id] = taskDialog; } DialogResult result = ConvertFromTaskDialogResult(taskDialog.Show()); if (tickEventHandler != null) { taskDialog.Tick -= new EventHandler <TaskDialogTickEventArgs>(internalTickEventHandler); } if (id != Guid.Empty) { lock (_taskDialogs) _taskDialogs.Remove(id); } return(result); }
/// <summary> /// Show generic user dialog with don't show this again option. /// </summary> /// <param name="windowTitleText">Title that appears in the title bar of the popup window.</param> /// <param name="title">Title that appears inside the popup window.</param> /// <param name="message">Detailed messages appearing in the popup window.</param> /// <param name="dontShowAgain">Boolean value indicating whether user selected don't sow this again.</param> /// <param name="buttons">Buttons to display.</param> /// <param name="icon">Icon to display.</param> /// <returns><code>TaskDialogResult</code> object indicating which option user selected.</returns> public static TaskDialogResult ShowDialogWithDontShowAgain(string windowTitleText, string title, string message, out bool dontShowAgain, TaskDialogStandardButtons buttons = TaskDialogStandardButtons.Ok, TaskDialogStandardIcon icon = TaskDialogStandardIcon.Information) { if (TaskDialog.IsPlatformSupported) { var taskdlg = new TaskDialog(); var button = buttons; taskdlg.Icon = icon; taskdlg.Caption = windowTitleText; taskdlg.InstructionText = title; taskdlg.Text = message; taskdlg.StandardButtons = button; taskdlg.FooterCheckBoxChecked = false; taskdlg.FooterCheckBoxText = string.Format("Don't show this for remaining items"); var result = taskdlg.Show(); dontShowAgain = taskdlg.FooterCheckBoxChecked.GetValueOrDefault(false); return(result); } else { dontShowAgain = false; var result = MessageBox.Show(message, windowTitleText, GetMessageBoxButtons(buttons), GetMessageBoxIcons(icon)); return(GetTaskDialogResult(result)); } }
private void buttonCreate_Click(object sender, EventArgs e) { if (editing) { /* Prevent duplicate elements by removing existing ones */ signature.Elements.Clear(); } if (signature.Category.Equals(string.Empty)) { signature.Category = "Uncategorised"; } foreach (HashSignatureElement file in files) { signature.Elements.Add(file); } foreach (ExtensionSignatureElement ext in extensions) { signature.Elements.Add(ext); } foreach (KeywordSignatureElement keyword in keywords) { signature.Elements.Add(keyword); } signature.LastWriteTime = DateTime.Now; try { signature.Save(AppFolders.CustomSignatureFolder); } catch (Exception) { MessageBox.Show( string.Format( "Unable to save the signature file to custom signature directory.{0}Detail: {1}", Environment.NewLine, AppFolders.CustomSignatureFolder), "Signature Editor", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); Close(); } if (editing) { /* Don't give the option to create more signatures */ Close(); } else { TaskDialogResult res; using (var dialog = new TaskDialog()) { TaskDialogStandardButtons button = TaskDialogStandardButtons.None; button |= TaskDialogStandardButtons.Yes; button |= TaskDialogStandardButtons.No; dialog.Icon = TaskDialogStandardIcon.Information; const string Title = "Signature Editor"; string instruction = "Signature saved"; const string Content = "Create another?"; dialog.StandardButtons = button; dialog.InstructionText = instruction; dialog.Caption = Title; dialog.Text = Content; res = dialog.Show(); } if (res == TaskDialogResult.Yes) { Reset(); } else { Close(); } } }
/// <summary>Shows either a <c>TaskDialog</c> or a <c>System.Windows.MessageBox</c> if running legacy windows.</summary> /// <param name="instructionText">The main text to display (Blue 14pt for <c>TaskDialog</c>).</param> /// <param name="icon">The icon to use.</param> /// <param name="standardButtons">The standard buttons to use (with or without the custom default button text).</param> /// <param name="description">A description of the message, supplements the instruction text.</param> /// <param name="footerText">Text to display as a footer message.</param> /// <param name="defaultButtonText">Text to display on the button.</param> /// <param name="displayShieldOnButton">Indicates if a UAC shield is to be displayed on the defaultButton.</param> static void ShowMessage( string instructionText, TaskDialogStandardIcon icon, TaskDialogStandardButtons standardButtons, string description = null, string footerText = null, string defaultButtonText = null, bool displayShieldOnButton = false) { if (TaskDialog.IsPlatformSupported) { using (var td = new TaskDialog()) { td.Caption = Resources.SevenUpdateSDK; td.InstructionText = instructionText; td.Text = description; td.Icon = icon; td.FooterText = footerText; td.FooterIcon = TaskDialogStandardIcon.Information; td.CanCancel = true; td.StandardButtons = standardButtons; if (defaultButtonText != null) { var button = new TaskDialogButton(@"btnCustom", defaultButtonText) { Default = true, ShowElevationIcon = displayShieldOnButton }; td.Controls.Add(button); } td.ShowDialog(Application.Current.MainWindow); return; } } string message = instructionText; var msgIcon = MessageBoxImage.None; if (description != null) { message += Environment.NewLine + description; } if (footerText != null) { message += Environment.NewLine + footerText; } switch (icon) { case TaskDialogStandardIcon.Error: msgIcon = MessageBoxImage.Error; break; case TaskDialogStandardIcon.Information: msgIcon = MessageBoxImage.Information; break; case TaskDialogStandardIcon.Warning: msgIcon = MessageBoxImage.Warning; break; } MessageBoxResult result; if (standardButtons == TaskDialogStandardButtons.Cancel || defaultButtonText != null) { result = MessageBox.Show(message, Resources.SevenUpdateSDK, MessageBoxButton.OKCancel, msgIcon); } else { result = MessageBox.Show(message, Resources.SevenUpdateSDK, MessageBoxButton.OK, msgIcon); } switch (result) { case MessageBoxResult.No: return; case MessageBoxResult.OK: return; case MessageBoxResult.Yes: return; default: return; } }
/// <summary> /// Show error dialog. /// </summary> /// <param name="windowTitleText">Title that appears in the title bar of the popup window.</param> /// <param name="title">Title that appears inside the popup window.</param> /// <param name="message">Detailed messages appearing in the popup window.</param> /// <param name="stackTrace">Stack trace.</param> /// <param name="buttons">Buttons to display.</param> /// <param name="icon">Icon to display.</param> /// <returns><code>TaskDialogResult</code> object indicating which option user selected.</returns> public static TaskDialogResult ShowErrorDialog(string windowTitleText, string title, string message, string stackTrace, TaskDialogStandardButtons buttons = TaskDialogStandardButtons.Ok, TaskDialogStandardIcon icon = TaskDialogStandardIcon.Error) { return(ShowDialog(windowTitleText, title, message, buttons, icon, stackTrace)); }
private void cmdShow_Click(object sender, EventArgs e) { TaskDialog td = new TaskDialog(); #region Button(s) TaskDialogStandardButtons button = TaskDialogStandardButtons.None; if (chkOK.Checked) { button |= TaskDialogStandardButtons.Ok; } if (chkCancel.Checked) { button |= TaskDialogStandardButtons.Cancel; } if (chkYes.Checked) { button |= TaskDialogStandardButtons.Yes; } if (chkNo.Checked) { button |= TaskDialogStandardButtons.No; } if (chkClose.Checked) { button |= TaskDialogStandardButtons.Close; } if (chkRetry.Checked) { button |= TaskDialogStandardButtons.Retry; } #endregion #region Icon if (rdoError.Checked) { td.Icon = TaskDialogStandardIcon.Error; } else if (rdoInformation.Checked) { td.Icon = TaskDialogStandardIcon.Information; } else if (rdoShield.Checked) { td.Icon = TaskDialogStandardIcon.Shield; } else if (rdoWarning.Checked) { td.Icon = TaskDialogStandardIcon.Warning; } #endregion #region Prompts string title = txtTitle.Text; string instruction = txtInstruction.Text; string content = txtContent.Text; #endregion td.StandardButtons = button; td.InstructionText = instruction; td.Caption = title; td.Text = content; td.OwnerWindowHandle = this.Handle; TaskDialogResult res = td.Show(); this.resultLbl.Text = "Result = " + res.ToString(); }
private void HandleRemovalAction(IList <FileItem> selectedItems, RemovalAction action) { const string DialogInstructionDelete = "The {0} selected file(s) will be permanently deleted."; const string DialogInstructionQuarantine = "The {0} selected file(s) will be moved into quarantine."; const string ErrorMessageDelete = "Unable to delete '{0}.'{1}Detail:{2}"; const string ErrorMessageQuarantine = "Unable to delete '{0}'.{1}Detail:{2}"; TaskDialogResult res; using (var td = new TaskDialog()) { TaskDialogStandardButtons button = TaskDialogStandardButtons.None; button |= TaskDialogStandardButtons.Yes; button |= TaskDialogStandardButtons.No; td.StandardButtons = button; td.StartupLocation = TaskDialogStartupLocation.CenterOwner; td.OwnerWindowHandle = this.Handle; td.Icon = TaskDialogStandardIcon.Information; td.InstructionText = action == RemovalAction.DELETE ? string.Format(DialogInstructionDelete, selectedItems.Count) : string.Format(DialogInstructionQuarantine, selectedItems.Count); td.Caption = action == RemovalAction.DELETE ? "Delete Selected Files?" : "Quarantine Selected Files?"; td.Text = "Do you want to continue?"; res = td.Show(); } if (res == TaskDialogResult.Yes) { foreach (FileItem file in selectedItems) { try { if (action == RemovalAction.QUARANTINE) { Quarantine.QuarantineManager.ImportFile(file); } else { File.Delete(file.AbsolutePath); } detections.Remove(file); } catch (Exception err) { MessageBox.Show( string.Format( action == RemovalAction.DELETE ? ErrorMessageDelete : ErrorMessageQuarantine, file.AbsolutePath, Environment.NewLine, err.Message), "Task Progress", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } listViewResults.Freeze(); listViewResults.SetObjects(detections); listViewResults.Unfreeze(); UpdateResultsCount(); updateResultButtonStatus(); } }
public static TaskDialog CreateMessageDialog(string caption, string message, TaskDialogStandardButtons buttons, TaskDialogStandardIcon icon) { return(CreateMessageDialog(caption, message, buttons, icon, IntPtr.Zero)); }
/// <summary> /// Show generic user dialog. /// </summary> /// <param name="windowTitleText">Title that appears in the title bar of the popup window.</param> /// <param name="title">Title that appears inside the popup window.</param> /// <param name="message">Detailed messages appearing in the popup window.</param> /// <param name="footerText">Footer text</param> /// <param name="buttons">Buttons to display.</param> /// <param name="icon">Icon to display.</param> /// <returns><code>TaskDialogResult</code> object indicating which option user selected.</returns> public static TaskDialogResult ShowDialog(string windowTitleText, string title, string message, TaskDialogStandardButtons buttons = TaskDialogStandardButtons.Ok, TaskDialogStandardIcon icon = TaskDialogStandardIcon.Information, string footerText = null) { if (TaskDialog.IsPlatformSupported) { var taskdlg = new TaskDialog { Icon = icon, Caption = windowTitleText, InstructionText = title, Text = message, StandardButtons = buttons }; if (!string.IsNullOrEmpty(footerText)) { taskdlg.DetailsExpandedLabel = "Hide Details"; taskdlg.DetailsCollapsedLabel = "Show Details"; taskdlg.DetailsExpandedText = footerText; taskdlg.ExpansionMode = TaskDialogExpandedDetailsLocation.ExpandFooter; } return(taskdlg.Show()); } else { var result = MessageBox.Show(message, windowTitleText, GetMessageBoxButtons(buttons), GetMessageBoxIcons(icon)); return(GetTaskDialogResult(result)); } }
/// <summary> /// Display "Vista-style" Task Dialog or fallback MessageBox() on pre-Vista machines. /// </summary> /// <param name="owner"></param> /// <param name="dialogTitle"></param> /// <param name="instruction"></param> /// <param name="body"></param> /// <param name="footer"></param> /// <param name="buttons"></param> /// <param name="mainIcon"></param> /// <param name="footerIcon"></param> /// <returns></returns> public static TaskDialogResult ShowMessageBox(IWin32Window owner, string dialogTitle, string instruction, string body, string footer, TaskDialogStandardButtons buttons, TaskDialogStandardIcon mainIcon, TaskDialogStandardIcon?footerIcon) { TaskDialogResult result = TaskDialogResult.Ok; if (CoreHelpers.RunningOnVista) // or greater { var dialog = new TaskDialog(); dialog.Cancelable = true; dialog.Caption = dialogTitle; if (footerIcon.HasValue) { dialog.FooterIcon = footerIcon.Value; } dialog.FooterText = footer; dialog.HyperlinksEnabled = true; dialog.HyperlinkClick += new EventHandler <TaskDialogHyperlinkClickedEventArgs>(dialog_HyperlinkClick); dialog.Icon = mainIcon; dialog.InstructionText = instruction; dialog.StandardButtons = buttons; dialog.Text = body; dialog.ExpansionMode = TaskDialogExpandedDetailsLocation.ExpandContent; dialog.StartupLocation = TaskDialogStartupLocation.CenterOwner; if (owner != null) { dialog.OwnerWindowHandle = owner.Handle; } return(dialog.Show()); } // XP or less MessageBoxButtons stdButtons = MessageBoxButtons.OK; if ((buttons & (TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No)) == (TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No)) { stdButtons = MessageBoxButtons.YesNo; } else if ((buttons & (TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No | TaskDialogStandardButtons.Cancel)) == (TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No | TaskDialogStandardButtons.Cancel)) { stdButtons = MessageBoxButtons.YesNoCancel; } else if ((buttons & (TaskDialogStandardButtons.Ok | TaskDialogStandardButtons.Cancel)) == (TaskDialogStandardButtons.Ok | TaskDialogStandardButtons.Cancel)) { stdButtons = MessageBoxButtons.OKCancel; } else if ((buttons & (TaskDialogStandardButtons.Ok | TaskDialogStandardButtons.Close)) == (TaskDialogStandardButtons.Ok | TaskDialogStandardButtons.Close)) { stdButtons = MessageBoxButtons.OK; } else if ((buttons & (TaskDialogStandardButtons.Retry | TaskDialogStandardButtons.Cancel)) == (TaskDialogStandardButtons.Retry | TaskDialogStandardButtons.Cancel)) { stdButtons = MessageBoxButtons.RetryCancel; } MessageBoxIcon stdIcon = MessageBoxIcon.None; if (mainIcon == TaskDialogStandardIcon.Information) { stdIcon = MessageBoxIcon.Information; } else if (mainIcon == TaskDialogStandardIcon.Error) { stdIcon = MessageBoxIcon.Error; } else if (mainIcon == TaskDialogStandardIcon.Warning) { stdIcon = MessageBoxIcon.Warning; } else if (mainIcon == TaskDialogStandardIcon.None) { stdIcon = MessageBoxIcon.None; } DialogResult stdResult = MessageBox.Show(owner, instruction + Environment.NewLine + body, APPLICATION_TITLE + " - " + dialogTitle, stdButtons, stdIcon); if (stdResult == DialogResult.OK) { result = TaskDialogResult.Ok; } else if (stdResult == DialogResult.Yes) { result = TaskDialogResult.Yes; } else if (stdResult == DialogResult.No) { result = TaskDialogResult.No; } else if (stdResult == DialogResult.Cancel) { result = TaskDialogResult.Cancel; } else if (stdResult == DialogResult.Retry) { result = TaskDialogResult.Retry; } return(result); }
public static TaskDialogResult ShowMessage(string caption, string message, TaskDialogStandardButtons buttons, TaskDialogStandardIcon icon, IntPtr owner) { return(CreateMessageDialog(caption, message, buttons, icon, owner).Show()); }
private void HandleRemovalAction( IList <QuarantineFileItem> selectedItems, RemovalAction action) { const string DialogInstructionDelete = "The {0} selected file(s) will be permanently deleted."; const string DialogInstructionRestore = "The {0} selected file(s) will be placed back in their original location."; const string ErrorMessageDelete = "Unable to delete '{0}.'{1}Detail:{2}"; const string ErrorMessageRestore = "Unable to restore '{0}'.{1}Detail:{2}"; TaskDialogResult res; using (var td = new TaskDialog()) { TaskDialogStandardButtons button = TaskDialogStandardButtons.None; button |= TaskDialogStandardButtons.Yes; button |= TaskDialogStandardButtons.No; td.StandardButtons = button; td.StartupLocation = TaskDialogStartupLocation.CenterOwner; td.OwnerWindowHandle = this.Handle; td.Icon = TaskDialogStandardIcon.Information; td.InstructionText = action == RemovalAction.DELETE ? string.Format(DialogInstructionDelete, selectedItems.Count) : string.Format(DialogInstructionRestore, selectedItems.Count); td.Caption = action == RemovalAction.DELETE ? "Delete Selected Files?" : "Quarantine Selected Files?"; td.Text = "Do you want to continue?"; res = td.Show(); } if (res == TaskDialogResult.Yes) { foreach (QuarantineFileItem file in selectedItems) { try { if (action == RemovalAction.RESTORE) { logger.Debug( "Restoring file: {0} to {1}", file.AbsolutePath, file.OriginalDirectoryPath); Quarantine.QuarantineManager.RestoreFile(file); } else { logger.Debug("Deleting file: {0}", file.AbsolutePath); Quarantine.QuarantineManager.RemoveFile(file, false); } } catch (Exception err) { logger.Error( err, string.Format("File handling failed for '{0}'", file.AbsolutePath)); MessageBox.Show( string.Format( action == RemovalAction.DELETE ? ErrorMessageDelete : ErrorMessageRestore, file.AbsolutePath, Environment.NewLine, err.Message), "Quarantine Manager", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } LoadFilesList(); } }