Example #1
0
        /// <summary>
        /// Create a TaskDialog from a TaskDialogConfig instance.
        /// </summary>
        /// <param name="taskConfig">A TaskDialogConfig instance that describes the TaskDialog.</param>
        /// <param name="button">The button that was clicked to close the TaskDialog.</param>
        /// <param name="radioButton">The radio button that was selected in the TaskDialog.</param>
        /// <param name="verificationFlagChecked">true if the verification checkbox was checked; false otherwise.</param>
        /// <returns></returns>
        public static int TaskDialogIndirect(TaskDialogConfig taskConfig, out int button, out int radioButton,
                                             out bool verificationFlagChecked)
        {
            ITaskDialog taskDialog;

            if (NativeTaskDialog.IsAvailableOnThisOs && !ForceEmulationMode)
            {
                taskDialog = new NativeTaskDialog();
            }
            else
            {
                taskDialog = new EmulatedTaskDialog(false);
            }

            return(taskDialog.TaskDialogIndirect(taskConfig, out button, out radioButton, out verificationFlagChecked));
        }
Example #2
0
        /// <exception cref="ArgumentException">Not supported yet.</exception>
        public static DialogResult ShowTaskDialogBox(IntPtr owner,
                                                     string title,
                                                     string mainInstruction,
                                                     string content,
                                                     string expandedInfo,
                                                     string footer,
                                                     string verificationText,
                                                     string radioButtons,
                                                     string commandButtons,
                                                     CommonButtons buttons,
                                                     CommonIcon mainIcon,
                                                     CommonIcon footerIcon,
                                                     int defaultIndex,
                                                     ProgressBarStyle progressBarStyle)
        {
            ITaskDialog taskDialog;

            if (NativeTaskDialog.IsAvailableOnThisOs && !ForceEmulationMode)
            {
                taskDialog = new NativeTaskDialog();
            }
            else
            {
                taskDialog = new EmulatedTaskDialog(false);
            }

            TaskConfig = new TaskDialogConfig();

            TaskConfig.Parent              = owner;
            TaskConfig.WindowTitle         = title;
            TaskConfig.MainInstruction     = mainInstruction;
            TaskConfig.Content             = content;
            TaskConfig.ExpandedInformation = expandedInfo;
            TaskConfig.Footer              = footer;

            // Radio Buttons
            if (!string.IsNullOrEmpty(radioButtons))
            {
                List <TaskDialogButton> lst = new List <TaskDialogButton>();
                string[] arr = radioButtons.Split(new[] { '|' });
                for (int i = 0; i < arr.Length; i++)
                {
                    try {
                        TaskDialogButton button = new TaskDialogButton {
                            ButtonId = 1000 + i, ButtonText = arr[i]
                        };
                        lst.Add(button);
                    } catch (FormatException) {}
                }
                TaskConfig.RadioButtons.AddRange(lst);
                TaskConfig.Flags.NoDefaultRadioButton = (defaultIndex == -1);
                if (defaultIndex >= 0)
                {
                    TaskConfig.DefaultRadioButton = defaultIndex + 1000;
                }
                else
                {
                    TaskConfig.DefaultRadioButton = 1000;
                }
            }

            // Custom Buttons
            if (!string.IsNullOrEmpty(commandButtons))
            {
                List <TaskDialogButton> lst = new List <TaskDialogButton>();
                string[] arr = commandButtons.Split(new[] { '|' });
                for (int i = 0; i < arr.Length; i++)
                {
                    try {
                        TaskDialogButton button = new TaskDialogButton {
                            ButtonId = 2000 + i, ButtonText = arr[i]
                        };
                        lst.Add(button);
                    } catch (FormatException) {}
                }
                TaskConfig.Buttons.AddRange(lst);
                if (defaultIndex >= 0)
                {
                    TaskConfig.DefaultButton = defaultIndex;
                }
            }

            TaskConfig.CommonButtons = buttons;
            TaskConfig.MainIcon      = mainIcon;
            if (TaskConfig.MainIcon == CommonIcon.Custom)
            {
                throw new ArgumentException("Not supported yet.", "mainIcon");
            }
            TaskConfig.FooterIcon = footerIcon;
            if (TaskConfig.FooterIcon == CommonIcon.Custom)
            {
                throw new ArgumentException("Not supported yet.", "footerIcon");
            }

            TaskConfig.Flags.EnableHyperLinks        = true;
            TaskConfig.Flags.ShowProgressBar         = (progressBarStyle == ProgressBarStyle.Continous) ? true : false;
            TaskConfig.Flags.ShowMarqueeProgressBar  = (progressBarStyle == ProgressBarStyle.Marquee) ? true : false;
            TaskConfig.Flags.AllowDialogCancellation = ((buttons & CommonButtons.Cancel) >= 0 ||
                                                        (buttons & CommonButtons.Close) >= 0);

            TaskConfig.Flags.CallbackTimer            = true;
            TaskConfig.Flags.ExpandedByDefault        = false;
            TaskConfig.Flags.ExpandFooterArea         = false;
            TaskConfig.Flags.PositionRelativeToWindow = true;
            TaskConfig.Flags.RtlLayout               = false;
            TaskConfig.Flags.CanBeMinimized          = false;
            TaskConfig.Flags.UseCommandLinks         = (TaskConfig.Buttons.Count > 0);
            TaskConfig.Flags.UseCommandLinksNoIcon   = false;
            TaskConfig.VerificationText              = verificationText;
            TaskConfig.Flags.VerificationFlagChecked = false;
            TaskConfig.ExpandedControlText           = "Hide details";
            TaskConfig.CollapsedControlText          = "Show details";

            taskDialog.Created             += TaskDialogCreated;
            taskDialog.ButtonClicked       += TaskDialogButtonClicked;
            taskDialog.HyperlinkClicked    += TaskDialogHyperlinkClicked;
            taskDialog.Timer               += TaskDialogTimer;
            taskDialog.Destroyed           += TaskDialogDestroyed;
            taskDialog.RadioButtonClicked  += TaskDialogRadioButtonClicked;
            taskDialog.DialogConstructed   += TaskDialogDialogConstructed;
            taskDialog.VerificationClicked += TaskDialogVerificationClicked;
            taskDialog.Help += TaskDialogHelp;
            taskDialog.ExpandoButtonClicked += TaskDialogExpandoButtonClicked;
            taskDialog.Navigated            += TaskDialogNavigated;

            DialogResult dialogResult = DialogResult.None;
            int          result       = taskDialog.TaskDialogIndirect(TaskConfig, out ButtonResult, out RadioButtonResult, out VerificationChecked);

            // Try to interpret the ButtonResult as a DialogResult
            try {
                if (ButtonResult < 1000)
                {
                    dialogResult = (DialogResult)ButtonResult;
                }
// ReSharper disable EmptyGeneralCatchClause
            } catch {}
// ReSharper restore EmptyGeneralCatchClause

            // if a command button was clicked, then change return result
            // to "DialogResult.OK" and set the CommandButtonResult)
            if (result >= 2000)
            {
                CommandButtonResult = result - 2000;
                dialogResult        = DialogResult.OK;
            }
            if (RadioButtonResult >= 1000)
            {
                // deduct the ButtonID start value for radio buttons
                RadioButtonResult -= 1000;
            }

            return(dialogResult);
        }