using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; namespace DevComponents.DotNetBar { /// /// Represent a task-dialog message box window. /// public static class TaskDialog { /// /// Displays TaskDialog message. /// /// Title of the window. /// Task dialog header. /// Task dialog text. /// Displayed buttons. /// Result from task-dialog. public static eTaskDialogResult Show(string dialogTitle, string dialogHeader, string dialogText, eTaskDialogButton dialogButtons) { TaskDialogInfo info = new TaskDialogInfo(dialogTitle, eTaskDialogIcon.Information, dialogHeader, dialogText, dialogButtons); return Show(info); } /// /// Displays TaskDialog message. /// /// Title of the window. /// Task dialog header. /// Task dialog text. /// Displayed buttons. /// Specifies the predefined color for the dialog. /// Result from task-dialog. public static eTaskDialogResult Show(string dialogTitle, string dialogHeader, string dialogText, eTaskDialogButton dialogButtons, eTaskDialogBackgroundColor dialogColor) { TaskDialogInfo info = new TaskDialogInfo(dialogTitle, eTaskDialogIcon.Information, dialogHeader, dialogText, dialogButtons, dialogColor); return Show(info); } /// /// Displays TaskDialog message. /// /// Title of the window. /// Icon displayed on dialog. /// Task dialog header. /// Task dialog text. /// Displayed buttons. /// Result from task-dialog. public static eTaskDialogResult Show(string dialogTitle, eTaskDialogIcon dialogIcon, string dialogHeader, string dialogText, eTaskDialogButton dialogButtons) { TaskDialogInfo info = new TaskDialogInfo(dialogTitle, dialogIcon, dialogHeader, dialogText, dialogButtons); return Show(info); } /// /// Displays TaskDialog message. /// /// Title of the window. /// Icon displayed on dialog. /// Task dialog header. /// Task dialog text. /// Displayed buttons. /// Specifies the predefined color for the dialog. /// Result from task-dialog. public static eTaskDialogResult Show(string dialogTitle, eTaskDialogIcon dialogIcon, string dialogHeader, string dialogText, eTaskDialogButton dialogButtons, eTaskDialogBackgroundColor dialogColor) { TaskDialogInfo info = new TaskDialogInfo(dialogTitle, dialogIcon, dialogHeader, dialogText, dialogButtons, dialogColor); return Show(info); } /// /// Displays TaskDialog message. /// /// Specifies the content of the task dialog. /// Result from task-dialog. public static eTaskDialogResult Show(TaskDialogInfo info) { return Show(null, info); } private static TaskDialogForm _TaskDialogForm = null; /// /// Displays TaskDialog message. /// /// Window owner of the task dialog. /// Specifies the content of the task dialog. /// Result from task-dialog. public static eTaskDialogResult Show(IWin32Window owner, TaskDialogInfo info) { eTaskDialogResult result = eTaskDialogResult.None; TaskDialogForm taskDialog = new TaskDialogForm(); try { _TaskDialogForm = taskDialog; if (!_AntiAlias) taskDialog.AntiAlias = _AntiAlias; taskDialog.EnableGlass = _EnableGlass && !StyleManager.IsMetro(StyleManager.Style); taskDialog.TopMost = info.TopMost; if (!info.FormCloseEnabled) taskDialog.CloseEnabled = false; taskDialog.ShowTaskDialog(owner, info); result = taskDialog.Result; } finally { taskDialog.Dispose(); _TaskDialogForm = null; } return result; } /// /// Closes the task dialog if it is open with eTaskDialogResult.None result. /// public static void Close() { Close(eTaskDialogResult.None); } /// /// Closes the task dialog if it is open with specified result value. /// /// Value that will be used as return value from Show method. public static void Close(eTaskDialogResult result) { if (_TaskDialogForm == null) throw new NullReferenceException("Task Dialog Form is not shown."); _TaskDialogForm.CloseDialog(result); } private static bool _EnableGlass = true; /// /// Gets or sets whether TaskDialog form has Windows Vista Glass enabled if running on /// Windows Vista with Glass enabled. Default value is true. /// public static bool EnableGlass { get { return _EnableGlass; } set { _EnableGlass = value; } } private static bool _AntiAlias = true; /// /// Gets or sets the anti-alias text-rendering setting for the controls on task-dialog. Default value is true. /// public static bool AntiAlias { get { return _AntiAlias; } set { _AntiAlias = value; } } internal static Image GetImage(eTaskDialogIcon icon) { if (icon == eTaskDialogIcon.None) return null; return BarFunctions.LoadBitmap("SystemImages.Task" + icon.ToString() + ".png"); } /// /// Occurs when any text markup link on Task-Dialog Box is clicked. Markup links can be created using "a" tag, for example: /// Markup link /// public static event MarkupLinkClickEventHandler MarkupLinkClick; internal static void InvokeMarkupLinkClick(object sender, MarkupLinkClickEventArgs e) { MarkupLinkClickEventHandler h = MarkupLinkClick; if (h != null) h(sender, e); } } /// /// Specifies the information displayed on task-dialog. /// public struct TaskDialogInfo { /// /// Initializes a new instance of the TaskDialogInfo structure. /// /// Title of dialog. /// Task-dialog icon /// Header text. /// Dialog main/content text. /// Dialog buttons displayed. /// Dialog background color. /// Radio Button Commands /// Button commands. /// Check-box command. /// Footer text /// Footer image. public TaskDialogInfo(string title, eTaskDialogIcon taskDialogIcon, string header, string text, eTaskDialogButton dialogButtons, eTaskDialogBackgroundColor dialogColor, Command[] radioButtons, Command[] buttons, Command checkBoxCommand, string footerText, Image footerImage) { _Title = title; _Header = header; _Text = text; _DialogButtons = dialogButtons; _DialogColor = dialogColor; _RadioButtons = radioButtons; _Buttons = buttons; _FooterText = footerText; _CheckBoxCommand = checkBoxCommand; _TaskDialogIcon = taskDialogIcon; _FooterImage = footerImage; _TopMost = false; _DefaultButton = eTaskDialogButton.Ok; _FormCloseEnabled = true; } /// /// Initializes a new instance of the TaskDialogInfo structure. /// /// Title of dialog. /// Task-dialog icon /// Header text. /// Dialog main/content text. /// Dialog buttons displayed. /// Dialog background color. /// Radio Button Commands /// Button commands. /// Check-box command. /// Footer text /// Footer image. /// Indicates whether TaskDialog is top most. public TaskDialogInfo(string title, eTaskDialogIcon taskDialogIcon, string header, string text, eTaskDialogButton dialogButtons, eTaskDialogBackgroundColor dialogColor, Command[] radioButtons, Command[] buttons, Command checkBoxCommand, string footerText, Image footerImage, bool topMost) { _Title = title; _Header = header; _Text = text; _DialogButtons = dialogButtons; _DialogColor = dialogColor; _RadioButtons = radioButtons; _Buttons = buttons; _FooterText = footerText; _CheckBoxCommand = checkBoxCommand; _TaskDialogIcon = taskDialogIcon; _FooterImage = footerImage; _TopMost = topMost; _DefaultButton = eTaskDialogButton.Ok; _FormCloseEnabled = true; } /// /// Initializes a new instance of the TaskDialogInfo structure. /// /// Title of dialog. /// Task-dialog icon /// Header text. /// Dialog main/content text. /// Dialog buttons displayed. /// Dialog background color. public TaskDialogInfo(string title, eTaskDialogIcon taskDialogIcon, string header, string text, eTaskDialogButton dialogButtons, eTaskDialogBackgroundColor dialogColor) { _Title = title; _Header = header; _Text = text; _DialogButtons = dialogButtons; _DialogColor = dialogColor; _RadioButtons = null; _Buttons = null; _FooterText = null; _CheckBoxCommand = null; _TaskDialogIcon = taskDialogIcon; _FooterImage = null; _TopMost = false; _DefaultButton = eTaskDialogButton.Ok; _FormCloseEnabled = true; } /// /// Initializes a new instance of the TaskDialogInfo structure. /// /// Title of dialog. /// Task-dialog icon /// Header text. /// Dialog main/content text. /// Dialog buttons displayed. public TaskDialogInfo(string title, eTaskDialogIcon taskDialogIcon, string header, string text, eTaskDialogButton dialogButtons) { _Title = title; _Header = header; _Text = text; _DialogButtons = dialogButtons; _DialogColor = eTaskDialogBackgroundColor.Default; _RadioButtons = null; _Buttons = null; _FooterText = null; _CheckBoxCommand = null; _TaskDialogIcon = taskDialogIcon; _FooterImage = null; _TopMost = false; _DefaultButton = eTaskDialogButton.Ok; _FormCloseEnabled = true; } /// /// Initializes a new instance of the TaskDialogInfo structure. /// /// Title of dialog. /// Task-dialog icon /// Header text. /// Dialog main/content text. /// Dialog buttons displayed. public TaskDialogInfo(string title, eTaskDialogIcon taskDialogIcon, string header, string text, eTaskDialogButton dialogButtons, eTaskDialogButton defaultButton) { _Title = title; _Header = header; _Text = text; _DialogButtons = dialogButtons; _DialogColor = eTaskDialogBackgroundColor.Default; _RadioButtons = null; _Buttons = null; _FooterText = null; _CheckBoxCommand = null; _TaskDialogIcon = taskDialogIcon; _FooterImage = null; _TopMost = false; _DefaultButton = defaultButton; _FormCloseEnabled = true; } private string _Title; /// /// Gets or sets the task-dialog window title. /// public string Title { get { return _Title; } set { _Title = value; } } private string _Header; /// /// Gets or sets the task-dialog header. /// public string Header { get { return _Header; } set { _Header = value; } } private string _Text; /// /// Gets or sets the task-dialog text. /// public string Text { get { return _Text; } set { _Text = value; } } private eTaskDialogButton _DialogButtons; /// /// Gets or sets the task-dialog buttons displayed. /// public eTaskDialogButton DialogButtons { get { return _DialogButtons; } set { _DialogButtons = value; } } private eTaskDialogBackgroundColor _DialogColor; /// /// Gets or sets the task-dialog background color. /// public eTaskDialogBackgroundColor DialogColor { get { return _DialogColor; } set { _DialogColor = value; } } private Command[] _RadioButtons; /// /// Gets or sets the array of commands that will be used to create the radio-buttons displayed on task-dialog. Each command will be executed as radio-buttons are checked by user. /// public Command[] RadioButtons { get { return _RadioButtons; } set { _RadioButtons = value; } } private Command[] _Buttons; /// /// Gets or sets the array of commands that will be used to create the buttons displayed on task-dialog. Each command will be executed as buttons are clicked by user. /// public Command[] Buttons { get { return _Buttons; } set { _Buttons = value; } } private string _FooterText; /// /// Gets or sets the footer text displayed on task-dialog. /// public string FooterText { get { return _FooterText; } set { _FooterText = value; } } private Command _CheckBoxCommand; /// /// Gets or sets the command that is used to initialize the footer check-box. Command will be executed when check-box state changes by end user. /// public Command CheckBoxCommand { get { return _CheckBoxCommand; } set { _CheckBoxCommand = value; } } private eTaskDialogIcon _TaskDialogIcon; /// /// Gets or sets the icon that is displayed on task dialog. /// public eTaskDialogIcon TaskDialogIcon { get { return _TaskDialogIcon; } set { _TaskDialogIcon = value; } } private Image _FooterImage; /// /// Gets or sets the image that is displayed in the task-dialog footer. Expected image size is 16x16 pixels. /// public Image FooterImage { get { return _FooterImage; } set { _FooterImage = value; } } private bool _TopMost; /// /// Gets or sets whether TaskDialog form is top-most. Default value is false. /// public bool TopMost { get { return _TopMost; } set { _TopMost = value; } } private eTaskDialogButton _DefaultButton; /// /// Gets or sets the TaskDialog default button. /// public eTaskDialogButton DefaultButton { get { return _DefaultButton; } set { _DefaultButton = value; } } private bool _FormCloseEnabled; /// /// Indicates whether task dialog form close button is enabled, default value is true. /// public bool FormCloseEnabled { get { return _FormCloseEnabled; } set { _FormCloseEnabled = value; } } } /// /// Specifies the task dialog buttons. /// [Flags] public enum eTaskDialogButton { /// /// OK button will be displayed. /// Ok = 1, /// /// Yes button will be displayed. /// Yes = 2, /// /// No button will be displayed. /// No = 4, /// /// Cancel button will be displayed. /// Cancel = 8, /// /// Retry button will be displayed. /// Retry = 16, /// /// Close button will be displayed. /// Close = 32 } /// /// Specifies the task dialog return values. /// public enum eTaskDialogResult { /// /// No button was clicked because dialog was closed using TaskDialog.Close method. /// None, /// /// OK button was clicked. /// Ok, /// /// Yes button was clicked. /// Yes, /// /// No button was clicked. /// No, /// /// Cancel button was clicked. /// Cancel, /// /// Retry button was clicked. /// Retry, /// /// Close button was clicked. /// Close, /// /// Specifies the custom result. Custom result can be specified if TaskDialog.Close method is called to close dialog. /// Custom1, /// /// Specifies the custom result. Custom result can be specified if TaskDialog.Close method is called to close dialog. /// Custom2, /// /// Specifies the custom result. Custom result can be specified if TaskDialog.Close method is called to close dialog. /// Custom3 } /// /// Define icons available on TaskDialog. /// public enum eTaskDialogIcon { /// /// No icon. /// None, /// /// Blue flag icon. /// BlueFlag, /// /// Blue stop icon. /// BlueStop, /// /// Light bulb, idea icon. /// Bulb, /// /// Check-mark icon. /// CheckMark, /// /// Check-mark icon. /// CheckMark2, /// /// Trash-can delete icon. /// Delete, /// /// Exclamation icon. /// Exclamation, /// /// Flag icon. /// Flag, /// /// Hand-stop icon. /// Hand, /// /// Help icon. /// Help, /// /// Informational icon. /// Information, /// /// Informational icon. /// Information2, /// /// No entry icon. /// NoEntry, /// /// Shield icon. /// Shield, /// /// Shield help icon. /// ShieldHelp, /// /// Shield OK icon. /// ShieldOk, /// /// Shield stop icon. /// ShieldStop, /// /// Stop icon. /// Stop, /// /// Stop icon. /// Stop2, /// /// Users icons. /// Users } }