Beispiel #1
0
        private static TaskDialogResult ShowEmulatedTaskDialog(TaskDialogOptions options)
        {
            TaskDialog          td   = new TaskDialog();
            TaskDialogViewModel tdvm = new TaskDialogViewModel(options);

            td.DataContext = tdvm;

            if (options.Owner != null)
            {
                td.Owner = options.Owner;
            }

            td.ShowDialog();

            TaskDialogResult result           = null;
            int diagResult                    = -1;
            TaskDialogSimpleResult simpResult = TaskDialogSimpleResult.None;
            bool verificationChecked          = false;
            int  radioButtonResult            = -1;
            int? commandButtonResult          = null;
            int? customButtonResult           = null;

            diagResult          = tdvm.DialogResult;
            radioButtonResult   = tdvm.RadioResult - RadioButtonIDOffset;
            verificationChecked = tdvm.VerificationChecked;

            if (diagResult >= CommandButtonIDOffset)
            {
                simpResult          = TaskDialogSimpleResult.Command;
                commandButtonResult = diagResult - CommandButtonIDOffset;
            }
            //else if (diagResult >= RadioButtonIDOffset)
            //{
            //    simpResult = (TaskDialogSimpleResult)diagResult;
            //    radioButtonResult = diagResult - RadioButtonIDOffset;
            //}
            else if (diagResult >= CustomButtonIDOffset)
            {
                simpResult         = TaskDialogSimpleResult.Custom;
                customButtonResult = diagResult - CustomButtonIDOffset;
            }
            // This occurs usually when the red X button is clicked
            else if (diagResult == -1)
            {
                simpResult = TaskDialogSimpleResult.Cancel;
            }
            else
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
            }

            result = new TaskDialogResult(
                simpResult,
                (String.IsNullOrEmpty(options.VerificationText) ? null : (bool?)verificationChecked),
                ((options.RadioButtons == null || options.RadioButtons.Length == 0) ? null : (int?)radioButtonResult),
                ((options.CommandButtons == null || options.CommandButtons.Length == 0) ? null : commandButtonResult),
                ((options.CustomButtons == null || options.CustomButtons.Length == 0) ? null : customButtonResult));

            return(result);
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskDialogResult"/> class.
 /// </summary>
 /// <param name="result">The simple TaskDialog result.</param>
 /// <param name="verificationChecked">Wether the verification checkbox was checked.</param>
 /// <param name="radioButtonResult">The radio button result, if any.</param>
 /// <param name="commandButtonResult">The command button result, if any.</param>
 /// <param name="customButtonResult">The custom button result, if any.</param>
 public TaskDialogResult(TaskDialogSimpleResult result, bool?verificationChecked = null, int?radioButtonResult = null, int?commandButtonResult = null, int?customButtonResult = null)
     : this()
 {
     Result = result;
     VerificationChecked = verificationChecked;
     RadioButtonResult   = radioButtonResult;
     CommandButtonResult = commandButtonResult;
     CustomButtonResult  = customButtonResult;
 }
Beispiel #3
0
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            TaskDialogSimpleResult res =
                TaskDialog.ShowMessage(
                    this,
                    "WARNING: Formatting will erase ALL data on this disk. To format the disk, click OK. To quit, click Cancel.",
                    "Format Local Disk (F:)",
                    TaskDialogCommonButtons.OKCancel,
                    VistaTaskDialogIcon.Warning);

            UpdateResult(res);
        }
Beispiel #4
0
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            TaskDialogSimpleResult res =
                TaskDialog.ShowMessage(this,
                                       "Outlook",
                                       "ActiveSync can't log on to Outlook",
                                       "Make sure that Outlook is installed and functioning correctly.",
                                       "You may need to restart your computer. You could have a conflict due to two folders on this computer are name C:\\Program Files\\Microsoft and C:\\Program Files\\Microsoft Office. If so, rename the C:\\Program Files\\Microsoft folder so that it does not contain the word \"Microsoft.\" If this folder contains subfolders, you may need to reinstall programs in the renamed folder.\n\nFor more information on renaming folders and installing programs, see Help for your operating system.",
                                       null,
                                       null,
                                       TaskDialogCommonButtons.Close,
                                       VistaTaskDialogIcon.Error,
                                       VistaTaskDialogIcon.None);

            UpdateResult(res);
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="TaskDialogResult"/> class.
		/// </summary>
		/// <param name="result">The simple TaskDialog result.</param>
		/// <param name="verificationChecked">Wether the verification checkbox was checked.</param>
		/// <param name="radioButtonResult">The radio button result, if any.</param>
		/// <param name="commandButtonResult">The command button result, if any.</param>
		/// <param name="customButtonResult">The custom button result, if any.</param>
		internal TaskDialogResult(TaskDialogSimpleResult result, bool? verificationChecked = null, int? radioButtonResult = null, int? commandButtonResult = null, int? customButtonResult = null)
			: this()
		{
			Result = result;
			VerificationChecked = verificationChecked;
			RadioButtonResult = radioButtonResult;
			CommandButtonResult = commandButtonResult;
			CustomButtonResult = customButtonResult;
		}
Beispiel #6
0
        private static TaskDialogResult ShowTaskDialog(TaskDialogOptions options)
        {
            VistaTaskDialog vtd = new VistaTaskDialog();

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

            if (options.CommandButtons != null && options.CommandButtons.Length > 0)
            {
                List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>();
                for (int i = 0; i < options.CommandButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId   = GetButtonIdForCommandButton(i);
                        button.ButtonText = options.CommandButtons[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                vtd.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0 &&
                    options.DefaultButtonIndex.Value < vtd.Buttons.Length)
                {
                    vtd.DefaultButton = vtd.Buttons[options.DefaultButtonIndex.Value].ButtonId;
                }
            }
            else if (options.RadioButtons != null && options.RadioButtons.Length > 0)
            {
                List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>();
                for (int i = 0; i < options.RadioButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId   = GetButtonIdForRadioButton(i);
                        button.ButtonText = options.RadioButtons[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                vtd.RadioButtons         = lst.ToArray();
                vtd.NoDefaultRadioButton = (!options.DefaultButtonIndex.HasValue || options.DefaultButtonIndex.Value == -1);
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0 &&
                    options.DefaultButtonIndex.Value < vtd.RadioButtons.Length)
                {
                    vtd.DefaultButton = vtd.RadioButtons[options.DefaultButtonIndex.Value].ButtonId;
                }
            }

            bool hasCustomCancel = false;

            if (options.CustomButtons != null && options.CustomButtons.Length > 0)
            {
                List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>();
                for (int i = 0; i < options.CustomButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId   = GetButtonIdForCustomButton(i);
                        button.ButtonText = options.CustomButtons[i];

                        if (!hasCustomCancel)
                        {
                            hasCustomCancel =
                                (button.ButtonText == "Close" ||
                                 button.ButtonText == "Cancel");
                        }

                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }

                vtd.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex.Value >= 0 &&
                    options.DefaultButtonIndex.Value < vtd.Buttons.Length)
                {
                    vtd.DefaultButton = vtd.Buttons[options.DefaultButtonIndex.Value].ButtonId;
                }
                vtd.CommonButtons = VistaTaskDialogCommonButtons.None;
            }
            else
            {
                vtd.CommonButtons = ConvertCommonButtons(options.CommonButtons);

                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0)
                {
                    vtd.DefaultButton = GetButtonIdForCommonButton(options.CommonButtons, options.DefaultButtonIndex.Value);
                }
            }

            vtd.MainIcon                = options.MainIcon;
            vtd.CustomMainIcon          = options.CustomMainIcon;
            vtd.FooterIcon              = options.FooterIcon;
            vtd.CustomFooterIcon        = options.CustomFooterIcon;
            vtd.EnableHyperlinks        = DetectHyperlinks(options.Content, options.ExpandedInfo, options.FooterText);
            vtd.AllowDialogCancellation =
                (options.AllowDialogCancellation ||
                 hasCustomCancel ||
                 options.CommonButtons == TaskDialogCommonButtons.Close ||
                 options.CommonButtons == TaskDialogCommonButtons.OKCancel ||
                 options.CommonButtons == TaskDialogCommonButtons.YesNoCancel);
            vtd.CallbackTimer            = options.EnableCallbackTimer;
            vtd.ExpandedByDefault        = options.ExpandedByDefault;
            vtd.ExpandFooterArea         = options.ExpandToFooter;
            vtd.PositionRelativeToWindow = true;
            vtd.RightToLeftLayout        = false;
            vtd.NoDefaultRadioButton     = false;
            vtd.CanBeMinimized           = false;
            vtd.ShowProgressBar          = options.ShowProgressBar;
            vtd.ShowMarqueeProgressBar   = options.ShowMarqueeProgressBar;
            vtd.UseCommandLinks          = (options.CommandButtons != null && options.CommandButtons.Length > 0);
            vtd.UseCommandLinksNoIcon    = false;
            vtd.VerificationText         = options.VerificationText;
            vtd.VerificationFlagChecked  = options.VerificationByDefault;
            vtd.ExpandedControlText      = "Hide details";
            vtd.CollapsedControlText     = "Show details";
            vtd.Callback     = options.Callback;
            vtd.CallbackData = options.CallbackData;
            vtd.Config       = options;

            TaskDialogResult result           = null;
            int diagResult                    = 0;
            TaskDialogSimpleResult simpResult = TaskDialogSimpleResult.None;
            bool verificationChecked          = false;
            int  radioButtonResult            = -1;
            int? commandButtonResult          = null;
            int? customButtonResult           = null;

            //diagResult = vtd.Show((vtd.CanBeMinimized ? null : options.Owner), out verificationChecked, out radioButtonResult);

            IntPtr ownerHandle = options.OwnerHandle;

            if (options.Owner != null)
            {
                WindowInteropHelper helper = new WindowInteropHelper(options.Owner);
                ownerHandle = helper.Owner;
            }
            diagResult = vtd.Show((vtd.CanBeMinimized ? IntPtr.Zero : ownerHandle), out verificationChecked, out radioButtonResult);


            if (diagResult >= CommandButtonIDOffset)
            {
                simpResult          = TaskDialogSimpleResult.Command;
                commandButtonResult = diagResult - CommandButtonIDOffset;
            }
            else if (radioButtonResult >= RadioButtonIDOffset)
            {
                simpResult         = (TaskDialogSimpleResult)diagResult;
                radioButtonResult -= RadioButtonIDOffset;
            }
            else if (diagResult >= CustomButtonIDOffset)
            {
                simpResult         = TaskDialogSimpleResult.Custom;
                customButtonResult = diagResult - CustomButtonIDOffset;
            }
            else
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
            }

            result = new TaskDialogResult(
                simpResult,
                (String.IsNullOrEmpty(options.VerificationText) ? null : (bool?)verificationChecked),
                ((options.RadioButtons == null || options.RadioButtons.Length == 0) ? null : (int?)radioButtonResult),
                ((options.CommandButtons == null || options.CommandButtons.Length == 0) ? null : commandButtonResult),
                ((options.CustomButtons == null || options.CustomButtons.Length == 0) ? null : customButtonResult));

            return(result);
        }
 private void UpdateResult(TaskDialogSimpleResult res)
 {
     lbResult.Text = "Task Dialog Result" + Environment.NewLine
         + "Simple Result: " + res.ToString();
 }
Beispiel #8
0
 private void UpdateResult(TaskDialogSimpleResult res)
 {
     lbResult.Text = "Task Dialog Result" + Environment.NewLine
                     + "Simple Result: " + res.ToString();
 }
Beispiel #9
0
        private static TaskDialogResult ShowTaskDialog(TaskDialogOptions options)
        {
            var td = new NativeTaskDialog();

            td.WindowTitle         = options.Title;
            td.MainInstruction     = options.MainInstruction;
            td.Content             = options.Content;
            td.ExpandedInformation = options.ExpandedInfo;
            td.Footer = options.FooterText;

            bool hasCustomCancel = false;

            // Use of Command Links overrides any custom defined buttons
            if (options.CommandLinks != null && options.CommandLinks.Length > 0)
            {
                List <TaskDialogButton> lst = new List <TaskDialogButton>();
                for (int i = 0; i < options.CommandLinks.Length; i++)
                {
                    try
                    {
                        TaskDialogButton button = new TaskDialogButton();
                        button.ButtonId   = GetButtonIdForCommandButton(i);
                        button.ButtonText = options.CommandLinks[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                td.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0 &&
                    options.DefaultButtonIndex.Value < td.Buttons.Length)
                {
                    td.DefaultButton = td.Buttons[options.DefaultButtonIndex.Value].ButtonId;
                }
            }
            else if (options.CustomButtons != null && options.CustomButtons.Length > 0)
            {
                List <TaskDialogButton> lst = new List <TaskDialogButton>();
                for (int i = 0; i < options.CustomButtons.Length; i++)
                {
                    try
                    {
                        TaskDialogButton button = new TaskDialogButton();
                        button.ButtonId   = GetButtonIdForCustomButton(i);
                        button.ButtonText = options.CustomButtons[i];

                        if (!hasCustomCancel)
                        {
                            hasCustomCancel =
                                (button.ButtonText == TaskDialogOptions.LocalizedStrings.CommonButton_Close ||
                                 button.ButtonText == TaskDialogOptions.LocalizedStrings.CommonButton_Cancel);
                        }

                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }

                td.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex.Value >= 0 &&
                    options.DefaultButtonIndex.Value < td.Buttons.Length)
                {
                    td.DefaultButton = td.Buttons[options.DefaultButtonIndex.Value].ButtonId;
                }
                td.CommonButtons = TaskDialogCommonButtons.None;
            }

            if (options.RadioButtons != null && options.RadioButtons.Length > 0)
            {
                List <TaskDialogButton> lst = new List <TaskDialogButton>();
                for (int i = 0; i < options.RadioButtons.Length; i++)
                {
                    try
                    {
                        TaskDialogButton button = new TaskDialogButton();
                        button.ButtonId   = GetButtonIdForRadioButton(i);
                        button.ButtonText = options.RadioButtons[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                td.RadioButtons         = lst.ToArray();
                td.NoDefaultRadioButton = (!options.DefaultButtonIndex.HasValue || options.DefaultButtonIndex.Value == -1);
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0 &&
                    options.DefaultButtonIndex.Value < td.RadioButtons.Length)
                {
                    td.DefaultButton = td.RadioButtons[options.DefaultButtonIndex.Value].ButtonId;
                }
            }

            if (options.CommonButtons != TaskDialogCommonButtons.None)
            {
                td.CommonButtons = options.CommonButtons;

                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0)
                {
                    td.DefaultButton = GetButtonIdForCommonButton(options.CommonButtons, options.DefaultButtonIndex.Value);
                }
            }

            td.MainIcon                = options.MainIcon;
            td.CustomMainIcon          = options.CustomMainIcon;
            td.FooterIcon              = options.FooterIcon;
            td.CustomFooterIcon        = options.CustomFooterIcon;
            td.EnableHyperlinks        = DetectHyperlinks(options.Content, options.ExpandedInfo, options.FooterText);
            td.AllowDialogCancellation =
                (options.AllowDialogCancellation ||
                 hasCustomCancel ||
                 options.CommonButtons.HasFlag(TaskDialogCommonButtons.Close) ||
                 options.CommonButtons.HasFlag(TaskDialogCommonButtons.Cancel));
            td.CallbackTimer            = options.EnableCallbackTimer;
            td.ExpandedByDefault        = options.ExpandedByDefault;
            td.ExpandFooterArea         = options.ExpandToFooter;
            td.PositionRelativeToWindow = true;
            td.RightToLeftLayout        = false;
            td.NoDefaultRadioButton     = false;
            td.CanBeMinimized           = false;
            td.ShowProgressBar          = options.ShowProgressBar;
            td.ShowMarqueeProgressBar   = options.ShowMarqueeProgressBar;
            td.UseCommandLinks          = (options.CommandLinks != null && options.CommandLinks.Length > 0);
            td.UseCommandLinksNoIcon    = false;
            td.VerificationText         = options.VerificationText;
            td.VerificationFlagChecked  = options.VerificationByDefault;
            td.ExpandedControlText      = "Hide details";
            td.CollapsedControlText     = "Show details";
            td.Callback     = options.Callback;
            td.CallbackData = options.CallbackData;
            td.Config       = options;

            TaskDialogResult result;
            int diagResult = 0;
            TaskDialogSimpleResult simpResult = TaskDialogSimpleResult.None;
            bool verificationChecked          = false;
            int  radioButtonResult            = -1;
            int? commandButtonResult          = null;
            int? customButtonResult           = null;

            diagResult = td.Show(options.Owner, out verificationChecked, out radioButtonResult);

            if (radioButtonResult >= RadioButtonIDOffset)
            {
                simpResult         = (TaskDialogSimpleResult)diagResult;
                radioButtonResult -= RadioButtonIDOffset;
            }

            if (diagResult >= CommandButtonIDOffset)
            {
                simpResult          = TaskDialogSimpleResult.Command;
                commandButtonResult = diagResult - CommandButtonIDOffset;
            }
            else if (diagResult >= CustomButtonIDOffset)
            {
                simpResult         = TaskDialogSimpleResult.Custom;
                customButtonResult = diagResult - CustomButtonIDOffset;
            }
            else
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
            }

            result = new TaskDialogResult(
                simpResult,
                (String.IsNullOrEmpty(options.VerificationText) ? null : (bool?)verificationChecked),
                ((options.RadioButtons == null || options.RadioButtons.Length == 0) ? null : (int?)radioButtonResult),
                ((options.CommandLinks == null || options.CommandLinks.Length == 0) ? null : commandButtonResult),
                ((options.CustomButtons == null || options.CustomButtons.Length == 0) ? null : customButtonResult));

            return(result);
        }