예제 #1
0
        /// <summary>
        ///   MessageBox for handling Choice for a number of dialogs, one button will be reserved to
        ///   answer for all option, if this is selected, it will be stored and returned in consecutive calls
        /// </summary>
        /// <param name="message">Dialog Message</param>
        /// <param name="title">Dialog Message</param>
        /// <param name="massChoice">
        ///   A class to maintain information if a default is chosen and how many dialogs might be presented
        /// </param>
        /// <param name="button1Text">By Default "Yes"</param>
        /// <param name="button2Text">By Default "No"</param>
        /// <returns>DialogResult.Yes or DialogResult.No</returns>

        public static DialogResult PersistentChoice(
            string message,
            string title,
            [NotNull] PersistentChoice massChoice,
            string button1Text = "Yes",
            string button2Text = "No")
        {
            if (massChoice.Chosen)
            {
                return(massChoice.DialogResult);
            }

            using (var tm = new TimedMessage())
            {
                var result = tm.ShowDialog(
                    message, title, // add a third button in case we expect followup dialogs
                    massChoice.NumRecs > 1 ? MessageBoxButtons.YesNoCancel : MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question,
                    // Depending on the massChoice Result, select the right button
                    massChoice.DialogResult == DialogResult.Yes ? MessageBoxDefaultButton.Button1 : MessageBoxDefaultButton.Button2,
                    4.0,
                    // do not overwrite Button 1 or Button 2
                    button1Text,
                    button2Text, // but set Button 3 if needed
                    massChoice.NumRecs > 1 ? $"{((massChoice.DialogResult == DialogResult.Yes) ? button1Text : button2Text)} To All ({massChoice.NumRecs})" : null);

                // Button3 results in Cancel and is the Mass choice
                if (result == DialogResult.Cancel)
                {
                    massChoice.Chosen = true;
                    return(massChoice.DialogResult);
                }
                return(result);
            }
        }
예제 #2
0
 public static DialogResult Show(
     string message,
     string title,
     MessageBoxButtons buttons             = MessageBoxButtons.OKCancel,
     MessageBoxIcon icon                   = MessageBoxIcon.None,
     MessageBoxDefaultButton defaultButton = MessageBoxDefaultButton.Button1,
     double timeout = 4.0)
 {
     using (var tm = new TimedMessage())
     {
         return(tm.ShowDialog(message, title, buttons, icon, defaultButton, timeout, null, null, null));
     }
 }
예제 #3
0
 public static DialogResult ShowBigHtml(
     string html,
     string title,
     MessageBoxButtons buttons             = MessageBoxButtons.OKCancel,
     MessageBoxIcon icon                   = MessageBoxIcon.None,
     MessageBoxDefaultButton defaultButton = MessageBoxDefaultButton.Button1,
     double timeout = 4.0)
 {
     if (html is null)
     {
         throw new System.ArgumentNullException(nameof(html));
     }
     using (var tm = new TimedMessage())
     {
         tm.Html = html;
         tm.Size = new Size(600, 450);
         return(tm.ShowDialog(null, title, buttons, icon, defaultButton, timeout, null, null, null));
     }
 }