/// <summary> /// Displays TaskDialog message. /// </summary> /// <param name="owner">Window owner of the task dialog.</param> /// <param name="info">Specifies the content of the task dialog.</param> /// <returns>Result from task-dialog.</returns> 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.Style != eStyle.Metro; taskDialog.TopMost = info.TopMost; taskDialog.ShowTaskDialog(owner, info); result = taskDialog.Result; } finally { taskDialog.Dispose(); _TaskDialogForm = null; } return result; }
/// <summary> /// Displays TaskDialog message. /// </summary> /// <param name="info">Specifies the content of the task dialog.</param> /// <returns>Result from task-dialog.</returns> public static eTaskDialogResult Show(TaskDialogInfo info) { return Show(null, info); }
/// <summary> /// Displays TaskDialog message. /// </summary> /// <param name="dialogTitle">Title of the window.</param> /// <param name="dialogHeader">Task dialog header.</param> /// <param name="dialogText">Task dialog text.</param> /// <param name="dialogButtons">Displayed buttons.</param> /// <returns>Result from task-dialog.</returns> 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); }
public eTaskDialogResult ShowTaskDialog(IWin32Window owner, TaskDialogInfo dialogInfo) { if (owner != null) this.StartPosition = FormStartPosition.CenterParent; else this.StartPosition = FormStartPosition.CenterScreen; UpdateDialogColor(dialogInfo); int dialogButtonsWidth = 20; int footerWidth = 0; int contentHeight = 32; this.Text = dialogInfo.Title; headerLabel.Text = dialogInfo.Header; contentLabel.Text = dialogInfo.Text; _DefaultButton = dialogInfo.DefaultButton; if (dialogInfo.TaskDialogIcon == eTaskDialogIcon.None) { int diff = this.Width - headerLabel.Right; headerLabel.Left = headerImage.Left; headerLabel.Width = this.Width - diff - headerLabel.Left; diff = this.Width - contentLabel.Right; contentLabel.Left = headerImage.Left; contentLabel.Width = this.Width - diff - contentLabel.Left; diff = this.Width - buttonsPanel.Right; buttonsPanel.Left = headerImage.Left; buttonsPanel.Width = this.Width - diff - buttonsPanel.Left; headerImage.Visible = false; } else headerImage.Image = TaskDialog.GetImage(dialogInfo.TaskDialogIcon); if (dialogInfo.CheckBoxCommand != null) { taskCheckBox.Command = dialogInfo.CheckBoxCommand; //taskCheckBox.Checked = dialogInfo.CheckBoxCommand.Checked; dialogButtonsWidth += taskCheckBox.Width + 12; } else taskCheckBox.Visible = false; if (!string.IsNullOrEmpty(dialogInfo.FooterText)) { footerLabel.Text = dialogInfo.FooterText; footerWidth += footerLabel.Width + 12; } else footerLabel.Visible = false; if (dialogInfo.FooterImage != null) { footerImage.Image = dialogInfo.FooterImage; footerWidth += footerImage.Width; } else { footerImage.Visible = false; footerLabel.Left = footerImage.Left; } if (dialogInfo.RadioButtons != null && dialogInfo.RadioButtons.Length > 0) { foreach (Command command in dialogInfo.RadioButtons) { CheckBoxItem item = new CheckBoxItem(); item.CheckBoxStyle = eCheckBoxStyle.RadioButton; //item.Checked = command.Checked; item.Command = command; buttonsPanel.Items.Add(item); } } if (dialogInfo.Buttons != null && dialogInfo.Buttons.Length > 0) { foreach (Command command in dialogInfo.Buttons) { ButtonItem item = new ButtonItem(); if (command.Image != null) { item.ButtonStyle = eButtonStyle.ImageAndText; item.ImagePosition = eImagePosition.Left; } item.Command = command; buttonsPanel.Items.Add(item); ButtonItemLayout.LayoutButton(item); footerWidth = Math.Max(footerWidth, item.WidthInternal + buttonsPanel.Left * 2); } } if ((dialogInfo.DialogButtons & eTaskDialogButton.Ok) == 0) { buttonOk.Visible = false; } else { dialogButtonsWidth += buttonOk.Width + 3; if (dialogInfo.DefaultButton == eTaskDialogButton.Ok) this.AcceptButton = buttonOk; } if ((dialogInfo.DialogButtons & eTaskDialogButton.Cancel) == 0) { buttonCancel.Visible = false; } else { dialogButtonsWidth += buttonCancel.Width + 3; this.CancelButton = buttonCancel; if (dialogInfo.DefaultButton == eTaskDialogButton.Cancel) this.AcceptButton = buttonCancel; } if ((dialogInfo.DialogButtons & eTaskDialogButton.Yes) == 0) { buttonYes.Visible = false; } else { dialogButtonsWidth += buttonYes.Width + 3; if (dialogInfo.DefaultButton == eTaskDialogButton.Yes) this.AcceptButton = buttonYes; } if ((dialogInfo.DialogButtons & eTaskDialogButton.No) == 0) { buttonNo.Visible = false; } else { dialogButtonsWidth += buttonNo.Width + 3; if (this.CancelButton == null) this.CancelButton = buttonNo; if (dialogInfo.DefaultButton == eTaskDialogButton.No) this.AcceptButton = buttonNo; } if ((dialogInfo.DialogButtons & eTaskDialogButton.Close) == 0) { buttonClose.Visible = false; } else { dialogButtonsWidth += buttonClose.Width + 3; if (this.CancelButton == null) this.CancelButton = buttonClose; else if (dialogInfo.DefaultButton == eTaskDialogButton.Close) this.AcceptButton = buttonClose; } if ((dialogInfo.DialogButtons & eTaskDialogButton.Retry) == 0) { buttonRetry.Visible = false; } else { dialogButtonsWidth += buttonRetry.Width + 3; if (dialogInfo.DefaultButton == eTaskDialogButton.Retry) this.AcceptButton = buttonRetry; } // If only OK button is visible it is cancel button as well if (dialogInfo.DialogButtons == eTaskDialogButton.Ok) this.CancelButton = buttonOk; if (string.IsNullOrEmpty(dialogInfo.FooterText) && dialogInfo.FooterImage == null) { footerPanel.Visible = false; bottomPanel.Height = flowLayoutPanel1.Height + 4; } else contentHeight += footerImage.Height; this.Width = Math.Max(MinimumWidth, Math.Max(footerWidth, dialogButtonsWidth)); using (Graphics g = headerLabel.CreateGraphics()) { } headerLabel.MaximumSize=new Size(headerLabel.Width, 1000); headerLabel.Height=headerLabel.GetPreferredSize(Size.Empty).Height; contentHeight += headerLabel.Height + 3; using (Graphics g = contentLabel.CreateGraphics()) { } contentLabel.Top = headerLabel.Bounds.Bottom + 3; contentLabel.MaximumSize = new Size(contentLabel.Width, 1000); contentLabel.Height=contentLabel.GetPreferredSize(Size.Empty).Height; contentHeight += contentLabel.Height + 3; if (contentLabel.IsUsingTextMarkup) contentHeight += 8; buttonsPanel.Top = contentLabel.Bottom + 3; if (buttonsPanel.Items.Count == 0) { buttonsPanel.Visible = false; } else { using (Graphics g = buttonsPanel.CreateGraphics()) { } buttonsPanel.Height = buttonsPanel.GetAutoSizeHeight() + 2; contentHeight += buttonsPanel.Height + 6; if (string.IsNullOrEmpty(dialogInfo.FooterText) && dialogInfo.FooterImage == null) contentHeight += 8; } contentHeight += bottomPanel.Height; this.Height = Math.Max(MinimumHeight, contentHeight); if (dialogInfo.TaskDialogIcon == eTaskDialogIcon.Help) System.Media.SystemSounds.Question.Play(); else if (dialogInfo.TaskDialogIcon == eTaskDialogIcon.Information) System.Media.SystemSounds.Asterisk.Play(); else System.Media.SystemSounds.Exclamation.Play(); LocalizeText(); ShowDialog(owner); return _Result; }
private void UpdateDialogColor(TaskDialogInfo dialogInfo) { eTaskDialogBackgroundColor color = dialogInfo.DialogColor; if (color == eTaskDialogBackgroundColor.Aqua) { //this.BackColor = ColorScheme.GetColor(0xDBEEF3); bottomPanel.Style.BackColor1.Color = ColorScheme.GetColor(0xDBEEF3); headerLabel.ForeColor = ColorScheme.GetColor(0x205867); contentLabel.ForeColor = ColorScheme.GetColor(0x205867); } else if (color == eTaskDialogBackgroundColor.Blue) { bottomPanel.Style.BackColor1.Color = ColorScheme.GetColor(0xDBE5F1); headerLabel.ForeColor = ColorScheme.GetColor(0x244061); contentLabel.ForeColor = ColorScheme.GetColor(0x244061); } else if (color == eTaskDialogBackgroundColor.DarkBlue) { bottomPanel.Style.BackColor1.Color = ColorScheme.GetColor(0xC6D9F0); headerLabel.ForeColor = ColorScheme.GetColor(0x0F243E); contentLabel.ForeColor = ColorScheme.GetColor(0x0F243E); } else if (color == eTaskDialogBackgroundColor.OliveGreen) { bottomPanel.Style.BackColor1.Color = ColorScheme.GetColor(0xEBF1DD); headerLabel.ForeColor = ColorScheme.GetColor(0x4F6128); contentLabel.ForeColor = ColorScheme.GetColor(0x4F6128); } else if (color == eTaskDialogBackgroundColor.Orange) { bottomPanel.Style.BackColor1.Color = ColorScheme.GetColor(0xFDEADA); headerLabel.ForeColor = ColorScheme.GetColor(0x974806); contentLabel.ForeColor = ColorScheme.GetColor(0x974806); } else if (color == eTaskDialogBackgroundColor.Purple) { bottomPanel.Style.BackColor1.Color = ColorScheme.GetColor(0xE5E0EC); headerLabel.ForeColor = ColorScheme.GetColor(0x3F3151); contentLabel.ForeColor = ColorScheme.GetColor(0x3F3151); } else if (color == eTaskDialogBackgroundColor.Red) { bottomPanel.Style.BackColor1.Color = ColorScheme.GetColor(0xF2DCDB); headerLabel.ForeColor = ColorScheme.GetColor(0x632423); contentLabel.ForeColor = ColorScheme.GetColor(0x632423); } else if (color == eTaskDialogBackgroundColor.Silver) { bottomPanel.Style.BackColor1.Color = ColorScheme.GetColor(0xF2F2F2); headerLabel.ForeColor = ColorScheme.GetColor(0x0C0C0C); contentLabel.ForeColor = ColorScheme.GetColor(0x0C0C0C); } else if (color == eTaskDialogBackgroundColor.Tan) { bottomPanel.Style.BackColor1.Color = ColorScheme.GetColor(0xDDD9C3); headerLabel.ForeColor = ColorScheme.GetColor(0x1D1B10); contentLabel.ForeColor = ColorScheme.GetColor(0x1D1B10); } if (color != eTaskDialogBackgroundColor.Default) bottomPanel.Style.BorderColor.Color = headerLabel.ForeColor; }
/// <summary> /// Displays TaskDialog message. /// </summary> /// <param name="dialogTitle">Title of the window.</param> /// <param name="dialogIcon">Icon displayed on dialog.</param> /// <param name="dialogHeader">Task dialog header.</param> /// <param name="dialogText">Task dialog text.</param> /// <param name="dialogButtons">Displayed buttons.</param> /// <param name="dialogColor">Specifies the predefined color for the dialog.</param> /// <returns>Result from task-dialog.</returns> 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); }