示例#1
0
        //--------------------------------------------------------------------------------
        public DialogResult ShowTaskDialogBox(IWin32Window Owner,
            string Title,
            string MainInstruction,
            string Content,
            string ExpandedInfo,
            string Footer,
            string VerificationText,
            string RadioButtons,
            string CommandButtons,
            TaskDialogButtons Buttons,
            SysIcons MainIcon,
            SysIcons FooterIcon,
            int DefaultIndex)
        {
            DialogResult result;
            if (OnTaskDialogShown != null)
                OnTaskDialogShown(null, EventArgs.Empty);

            if (VistaTaskDialog.IsAvailableOnThisOS)
            {
                // [OPTION 1] Show Vista TaskDialog
                VistaTaskDialog vtd = new VistaTaskDialog();

                vtd.WindowTitle = Title;
                vtd.MainInstruction = MainInstruction;
                vtd.Content = Content;
                vtd.ExpandedInformation = ExpandedInfo;
                vtd.Footer = Footer;

                // Radio Buttons
                if (RadioButtons != "")
                {
                    List<VistaTaskDialogButton> lst = new List<VistaTaskDialogButton>();
                    string[] arr = RadioButtons.Split(new char[] {'|'});
                    for (int i = 0; i < arr.Length; i++)
                    {
                        try
                        {
                            VistaTaskDialogButton button = new VistaTaskDialogButton();
                            button.ButtonId = 1000 + i;
                            button.ButtonText = arr[i];
                            lst.Add(button);
                        }
                        catch (FormatException)
                        {
                        }
                    }
                    vtd.RadioButtons = lst.ToArray();
                    vtd.NoDefaultRadioButton = (DefaultIndex == -1);
                    if (DefaultIndex >= 0)
                        vtd.DefaultRadioButton = DefaultIndex;
                }

                // Custom Buttons
                if (CommandButtons != "")
                {
                    List<VistaTaskDialogButton> lst = new List<VistaTaskDialogButton>();
                    string[] arr = CommandButtons.Split(new char[] {'|'});
                    for (int i = 0; i < arr.Length; i++)
                    {
                        try
                        {
                            VistaTaskDialogButton button = new VistaTaskDialogButton();
                            button.ButtonId = 2000 + i;
                            button.ButtonText = arr[i];
                            lst.Add(button);
                        }
                        catch (FormatException)
                        {
                        }
                    }
                    vtd.Buttons = lst.ToArray();
                    if (DefaultIndex >= 0)
                        vtd.DefaultButton = DefaultIndex;
                }

                switch (Buttons)
                {
                    case TaskDialogButtons.YesNo:
                        vtd.CommonButtons = VistaTaskDialogCommonButtons.Yes | VistaTaskDialogCommonButtons.No;
                        break;
                    case TaskDialogButtons.YesNoCancel:
                        vtd.CommonButtons = VistaTaskDialogCommonButtons.Yes | VistaTaskDialogCommonButtons.No |
                                            VistaTaskDialogCommonButtons.Cancel;
                        break;
                    case TaskDialogButtons.OKCancel:
                        vtd.CommonButtons = VistaTaskDialogCommonButtons.Ok | VistaTaskDialogCommonButtons.Cancel;
                        break;
                    case TaskDialogButtons.OK:
                        vtd.CommonButtons = VistaTaskDialogCommonButtons.Ok;
                        break;
                    case TaskDialogButtons.Close:
                        vtd.CommonButtons = VistaTaskDialogCommonButtons.Close;
                        break;
                    case TaskDialogButtons.Cancel:
                        vtd.CommonButtons = VistaTaskDialogCommonButtons.Cancel;
                        break;
                    default:
                        vtd.CommonButtons = 0;
                        break;
                }

                switch (MainIcon)
                {
                    case SysIcons.Information:
                        vtd.MainIcon = VistaTaskDialogIcon.Information;
                        break;
                    case SysIcons.Question:
                        vtd.MainIcon = VistaTaskDialogIcon.Question;
                        break;
                    case SysIcons.Warning:
                        vtd.MainIcon = VistaTaskDialogIcon.Warning;
                        break;
                    case SysIcons.Error:
                        vtd.MainIcon = VistaTaskDialogIcon.Error;
                        break;
                }

                switch (FooterIcon)
                {
                    case SysIcons.Information:
                        vtd.FooterIcon = VistaTaskDialogIcon.Information;
                        break;
                    case SysIcons.Question:
                        vtd.FooterIcon = VistaTaskDialogIcon.Question;
                        break;
                    case SysIcons.Warning:
                        vtd.FooterIcon = VistaTaskDialogIcon.Warning;
                        break;
                    case SysIcons.Error:
                        vtd.FooterIcon = VistaTaskDialogIcon.Error;
                        break;
                }

                vtd.EnableHyperlinks = true;
                vtd.ShowProgressBar = false;
                vtd.AllowDialogCancellation = (Buttons == TaskDialogButtons.Cancel ||
                                               Buttons == TaskDialogButtons.Close ||
                                               Buttons == TaskDialogButtons.OKCancel ||
                                               Buttons == TaskDialogButtons.YesNoCancel);
                vtd.CallbackTimer = false;
                vtd.ExpandedByDefault = false;
                vtd.ExpandFooterArea = false;
                vtd.PositionRelativeToWindow = true;
                vtd.RightToLeftLayout = false;
                vtd.NoDefaultRadioButton = false;
                vtd.CanBeMinimized = false;
                vtd.ShowMarqueeProgressBar = false;
                vtd.UseCommandLinks = (CommandButtons != "");
                vtd.UseCommandLinksNoIcon = false;
                vtd.VerificationText = VerificationText;
                vtd.VerificationFlagChecked = false;
                vtd.ExpandedControlText = Locale.localizedString("More Options", "Bookmark");
                vtd.CollapsedControlText = Locale.localizedString("More Options", "Bookmark");
                vtd.Callback =
                    delegate(VistaActiveTaskDialog taskDialog, VistaTaskDialogNotificationArgs args, object callbackData)
                        {
                            if (!String.IsNullOrEmpty(args.Hyperlink))
                            {
                                HelpDelegate(args.Hyperlink);
                            }
                            return false;
                        };

                // Show the Dialog
                result =
                    (DialogResult)
                    vtd.Show((vtd.CanBeMinimized ? null : Owner), out _verificationChecked, out _radioButtonResult);

                // if a command button was clicked, then change return result
                // to "DialogResult.OK" and set the CommandButtonResult
                if ((int) result >= 2000)
                {
                    CommandButtonResult = ((int) result - 2000);
                    result = DialogResult.OK;
                }
                if (RadioButtonResult >= 1000)
                    RadioButtonResult -= 1000; // deduct the ButtonID start value for radio buttons
            }
            else
            {
                // [OPTION 2] Show Emulated Form
                using (TaskDialogForm td = new TaskDialogForm())
                {
                    td.Title = Title;
                    td.MainInstruction = MainInstruction;
                    td.Content = Content;
                    td.ExpandedInfo = ExpandedInfo;
                    td.Footer = Footer;
                    td.RadioButtons = RadioButtons;
                    td.CommandButtons = CommandButtons;
                    td.PlaySystemSounds = PlaySystemSounds;
                    td.Buttons = Buttons;
                    td.MainIcon = MainIcon;
                    td.FooterIcon = FooterIcon;
                    td.VerificationText = VerificationText;
                    td.Width = EmulatedFormWidth;
                    td.DefaultButtonIndex = DefaultIndex;
                    td.BuildForm();
                    result = td.ShowDialog(Owner);

                    RadioButtonResult = td.RadioButtonIndex;
                    CommandButtonResult = td.CommandButtonClickedIndex;
                    VerificationChecked = td.VerificationCheckBoxChecked;
                }
            }
            if (OnTaskDialogClosed != null)
                OnTaskDialogClosed(null, EventArgs.Empty);
            return result;
        }
示例#2
0
        //--------------------------------------------------------------------------------

        #region ShowTaskDialogBox

        //--------------------------------------------------------------------------------
        public DialogResult ShowTaskDialogBox(IWin32Window Owner,
                                              string Title,
                                              string MainInstruction,
                                              string Content,
                                              string ExpandedInfo,
                                              string Footer,
                                              string VerificationText,
                                              string RadioButtons,
                                              string CommandButtons,
                                              TaskDialogButtons Buttons,
                                              SysIcons MainIcon,
                                              SysIcons FooterIcon,
                                              int DefaultIndex)

        {
            DialogResult result;

            if (OnTaskDialogShown != null)
            {
                OnTaskDialogShown(null, EventArgs.Empty);
            }

            if (VistaTaskDialog.IsAvailableOnThisOS)
            {
                // [OPTION 1] Show Vista TaskDialog
                VistaTaskDialog vtd = new VistaTaskDialog();

                vtd.WindowTitle         = Title;
                vtd.MainInstruction     = MainInstruction;
                vtd.Content             = Content;
                vtd.ExpandedInformation = ExpandedInfo;
                vtd.Footer = Footer;

                // Radio Buttons
                if (RadioButtons != "")
                {
                    List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>();
                    string[] arr = RadioButtons.Split(new char[] { '|' });
                    for (int i = 0; i < arr.Length; i++)
                    {
                        try
                        {
                            VistaTaskDialogButton button = new VistaTaskDialogButton();
                            button.ButtonId   = 1000 + i;
                            button.ButtonText = arr[i];
                            lst.Add(button);
                        }
                        catch (FormatException)
                        {
                        }
                    }
                    vtd.RadioButtons         = lst.ToArray();
                    vtd.NoDefaultRadioButton = (DefaultIndex == -1);
                    if (DefaultIndex >= 0)
                    {
                        vtd.DefaultRadioButton = DefaultIndex;
                    }
                }

                // Custom Buttons
                if (CommandButtons != "")
                {
                    List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>();
                    string[] arr = CommandButtons.Split(new char[] { '|' });
                    for (int i = 0; i < arr.Length; i++)
                    {
                        try
                        {
                            VistaTaskDialogButton button = new VistaTaskDialogButton();
                            button.ButtonId   = 2000 + i;
                            button.ButtonText = arr[i];
                            lst.Add(button);
                        }
                        catch (FormatException)
                        {
                        }
                    }
                    vtd.Buttons = lst.ToArray();
                    if (DefaultIndex >= 0)
                    {
                        vtd.DefaultButton = DefaultIndex;
                    }
                }

                switch (Buttons)
                {
                case TaskDialogButtons.YesNo:
                    vtd.CommonButtons = VistaTaskDialogCommonButtons.Yes | VistaTaskDialogCommonButtons.No;
                    break;

                case TaskDialogButtons.YesNoCancel:
                    vtd.CommonButtons = VistaTaskDialogCommonButtons.Yes | VistaTaskDialogCommonButtons.No |
                                        VistaTaskDialogCommonButtons.Cancel;
                    break;

                case TaskDialogButtons.OKCancel:
                    vtd.CommonButtons = VistaTaskDialogCommonButtons.Ok | VistaTaskDialogCommonButtons.Cancel;
                    break;

                case TaskDialogButtons.OK:
                    vtd.CommonButtons = VistaTaskDialogCommonButtons.Ok;
                    break;

                case TaskDialogButtons.Close:
                    vtd.CommonButtons = VistaTaskDialogCommonButtons.Close;
                    break;

                case TaskDialogButtons.Cancel:
                    vtd.CommonButtons = VistaTaskDialogCommonButtons.Cancel;
                    break;

                default:
                    vtd.CommonButtons = 0;
                    break;
                }

                switch (MainIcon)
                {
                case SysIcons.Information:
                    vtd.MainIcon = VistaTaskDialogIcon.Information;
                    break;

                case SysIcons.Question:
                    vtd.MainIcon = VistaTaskDialogIcon.Question;
                    break;

                case SysIcons.Warning:
                    vtd.MainIcon = VistaTaskDialogIcon.Warning;
                    break;

                case SysIcons.Error:
                    vtd.MainIcon = VistaTaskDialogIcon.Error;
                    break;
                }

                switch (FooterIcon)
                {
                case SysIcons.Information:
                    vtd.FooterIcon = VistaTaskDialogIcon.Information;
                    break;

                case SysIcons.Question:
                    vtd.FooterIcon = VistaTaskDialogIcon.Question;
                    break;

                case SysIcons.Warning:
                    vtd.FooterIcon = VistaTaskDialogIcon.Warning;
                    break;

                case SysIcons.Error:
                    vtd.FooterIcon = VistaTaskDialogIcon.Error;
                    break;
                }

                vtd.EnableHyperlinks        = true;
                vtd.ShowProgressBar         = false;
                vtd.AllowDialogCancellation = (Buttons == TaskDialogButtons.Cancel ||
                                               Buttons == TaskDialogButtons.Close ||
                                               Buttons == TaskDialogButtons.OKCancel ||
                                               Buttons == TaskDialogButtons.YesNoCancel);
                vtd.CallbackTimer            = false;
                vtd.ExpandedByDefault        = false;
                vtd.ExpandFooterArea         = false;
                vtd.PositionRelativeToWindow = true;
                vtd.RightToLeftLayout        = false;
                vtd.NoDefaultRadioButton     = false;
                vtd.CanBeMinimized           = false;
                vtd.ShowMarqueeProgressBar   = false;
                vtd.UseCommandLinks          = (CommandButtons != "");
                vtd.UseCommandLinksNoIcon    = false;
                vtd.VerificationText         = VerificationText;
                vtd.VerificationFlagChecked  = false;
                vtd.ExpandedControlText      = Locale.localizedString("More Options", "Bookmark");
                vtd.CollapsedControlText     = Locale.localizedString("More Options", "Bookmark");
                vtd.Callback =
                    delegate(VistaActiveTaskDialog taskDialog, VistaTaskDialogNotificationArgs args, object callbackData)
                {
                    if (!String.IsNullOrEmpty(args.Hyperlink))
                    {
                        HelpDelegate(args.Hyperlink);
                    }
                    return(false);
                };

                // Show the Dialog
                result =
                    (DialogResult)
                    vtd.Show((vtd.CanBeMinimized ? null : Owner), out _verificationChecked, out _radioButtonResult);

                // if a command button was clicked, then change return result
                // to "DialogResult.OK" and set the CommandButtonResult
                if ((int)result >= 2000)
                {
                    CommandButtonResult = ((int)result - 2000);
                    result = DialogResult.OK;
                }
                if (RadioButtonResult >= 1000)
                {
                    RadioButtonResult -= 1000; // deduct the ButtonID start value for radio buttons
                }
            }
            else
            {
                // [OPTION 2] Show Emulated Form
                using (TaskDialogForm td = new TaskDialogForm())
                {
                    td.Title              = Title;
                    td.MainInstruction    = MainInstruction;
                    td.Content            = Content;
                    td.ExpandedInfo       = ExpandedInfo;
                    td.Footer             = Footer;
                    td.RadioButtons       = RadioButtons;
                    td.CommandButtons     = CommandButtons;
                    td.PlaySystemSounds   = PlaySystemSounds;
                    td.Buttons            = Buttons;
                    td.MainIcon           = MainIcon;
                    td.FooterIcon         = FooterIcon;
                    td.VerificationText   = VerificationText;
                    td.Width              = EmulatedFormWidth;
                    td.DefaultButtonIndex = DefaultIndex;
                    td.BuildForm();
                    result = td.ShowDialog(Owner);

                    RadioButtonResult   = td.RadioButtonIndex;
                    CommandButtonResult = td.CommandButtonClickedIndex;
                    VerificationChecked = td.VerificationCheckBoxChecked;
                }
            }
            if (OnTaskDialogClosed != null)
            {
                OnTaskDialogClosed(null, EventArgs.Empty);
            }
            return(result);
        }