/// <summary>
        /// TaskDialog wrapped in a CommonDialog class. THis is required to work well in
        /// MMC 2.1. In MMC 2.1 you must use the ShowDialog methods on the MMC classes to
        /// correctly show a modal dialog. This class will allow you to do this and keep access
        /// to the results of the TaskDialog.
        /// </summary>
        /// <param name="taskDialog">The TaskDialog to show.</param>
        public VistaTaskDialogCommonDialog(VistaTaskDialog taskDialog)
        {
            if (taskDialog == null)
            {
                throw new ArgumentNullException("taskDialog");
            }

            this.taskDialog = taskDialog;
        }
예제 #2
0
        //--------------------------------------------------------------------------------
        public static DialogResult ShowTaskDialogBox(IWin32Window Owner,
                                                 string Title,
                                                 string MainInstruction,
                                                 string Content,
                                                 string ExpandedInfo,
                                                 string Footer,
                                                 string VerificationText,
                                                 string RadioButtons,
                                                 string CommandButtons,
                                                 eTaskDialogButtons Buttons,
                                                 eSysIcons MainIcon,
                                                 eSysIcons FooterIcon,
                                                 int DefaultIndex)
        {
            DialogResult result;
              if (OnTaskDialogShown != null)
            OnTaskDialogShown(null, EventArgs.Empty);

              if (VistaTaskDialog.IsAvailableOnThisOS && !ForceEmulationMode)
              {
            // [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 eTaskDialogButtons.YesNo:
            vtd.CommonButtons = VistaTaskDialogCommonButtons.Yes | VistaTaskDialogCommonButtons.No;
            break;
              case eTaskDialogButtons.YesNoCancel:
            vtd.CommonButtons = VistaTaskDialogCommonButtons.Yes | VistaTaskDialogCommonButtons.No | VistaTaskDialogCommonButtons.Cancel;
            break;
              case eTaskDialogButtons.OKCancel:
            vtd.CommonButtons = VistaTaskDialogCommonButtons.Ok | VistaTaskDialogCommonButtons.Cancel;
            break;
              case eTaskDialogButtons.OK:
            vtd.CommonButtons = VistaTaskDialogCommonButtons.Ok;
            break;
              case eTaskDialogButtons.Close:
            vtd.CommonButtons = VistaTaskDialogCommonButtons.Close;
            break;
              case eTaskDialogButtons.Cancel:
            vtd.CommonButtons = VistaTaskDialogCommonButtons.Cancel;
            break;
              default:
            vtd.CommonButtons = 0;
            break;
            }

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

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

            vtd.EnableHyperlinks = false;
            vtd.ShowProgressBar = false;
            vtd.AllowDialogCancellation = (Buttons == eTaskDialogButtons.Cancel ||
                                       Buttons == eTaskDialogButtons.Close ||
                                       Buttons == eTaskDialogButtons.OKCancel ||
                                       Buttons == eTaskDialogButtons.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 = "Hide details";
            vtd.CollapsedControlText = "Show details";
            vtd.Callback = null;

            // 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 (frmTaskDialog td = new frmTaskDialog())
            {
              td.Title = Title;
              td.MainInstruction = MainInstruction;
              td.Content = Content;
              td.ExpandedInfo = ExpandedInfo;
              td.Footer = Footer;
              td.RadioButtons = RadioButtons;
              td.CommandButtons = CommandButtons;
              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;
        }