/// <summary> /// Displays a <see cref="TaskDialog"/>. /// </summary> /// <param name="taskDialog">The <see cref="TaskDialog"/> to display.</param> /// <param name="owner">The parent window the displayed window is modal to; can be <c>null</c>.</param> /// <returns>Indicates the button the user pressed.</returns> /// <exception cref="BadImageFormatException">The task-dialog DLL could not be loaded.</exception> /// <exception cref="EntryPointNotFoundException">The task-dialog DLL routine could not be called.</exception> private static DialogResult ShowTaskDialog([NotNull] TaskDialog.TaskDialog taskDialog, [CanBeNull] IWin32Window owner) { // Note: If you get an EntryPointNotFoundException here, add this to your application manifest and test outside the IDE: // <dependency> // <dependentAssembly> // <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" /> // </dependentAssembly> // </dependency> int result = (owner == null) ? taskDialog.Show() : taskDialog.Show(owner); return((DialogResult)result); }
/// <summary> /// Displays a message using a <see cref="TaskDialog"/>. /// </summary> /// <param name="text">The message to be displayed.</param> /// <param name="severity">How severe/important the message is.</param> private static TaskDialog.TaskDialog GetTaskDialog([NotNull, Localizable(true)] string text, MsgSeverity severity) { // Split everything from the second line onwards off from the main text string[] split = text.Replace("\r\n", "\n").Split(new[] { '\n' }, 2); var taskDialog = new TaskDialog.TaskDialog { PositionRelativeToWindow = true, WindowTitle = Application.ProductName, MainInstruction = split[0] }; if (split.Length == 2) { taskDialog.Content = split[1]; } // Handle RTL systems taskDialog.RightToLeftLayout = CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft; // Select icon based on message severity switch (severity) { case MsgSeverity.Warn: taskDialog.MainIcon = TaskDialogIcon.Warning; taskDialog.AllowDialogCancellation = true; break; case MsgSeverity.Error: taskDialog.MainIcon = TaskDialogIcon.Error; taskDialog.AllowDialogCancellation = false; // Real errors shouldn't be easily ESCed away break; default: case MsgSeverity.Info: taskDialog.MainIcon = TaskDialogIcon.Information; taskDialog.AllowDialogCancellation = true; break; } return(taskDialog); }
/// <summary> /// Displays a message using a <see cref="TaskDialog"/>. /// </summary> /// <param name="text">The message to be displayed.</param> /// <param name="severity">How severe/important the message is.</param> private static TaskDialog.TaskDialog GetTaskDialog([NotNull, Localizable(true)] string text, MsgSeverity severity) { // Split everything from the second line onwards off from the main text string[] split = text.Replace("\r\n", "\n").Split(new[] {'\n'}, 2); var taskDialog = new TaskDialog.TaskDialog { PositionRelativeToWindow = true, WindowTitle = Application.ProductName, MainInstruction = split[0] }; if (split.Length == 2) taskDialog.Content = split[1]; // Handle RTL systems taskDialog.RightToLeftLayout = CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft; // Select icon based on message severity switch (severity) { case MsgSeverity.Warn: taskDialog.MainIcon = TaskDialogIcon.Warning; taskDialog.AllowDialogCancellation = true; break; case MsgSeverity.Error: taskDialog.MainIcon = TaskDialogIcon.Error; taskDialog.AllowDialogCancellation = false; // Real errors shouldn't be easily ESCed away break; default: case MsgSeverity.Info: taskDialog.MainIcon = TaskDialogIcon.Information; taskDialog.AllowDialogCancellation = true; break; } return taskDialog; }