question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[DialogResult] Add TryAgain and Continue (result 10, and 11) respectively.

See original GitHub issue

Is your feature request related to a problem? Please describe.

Nope, I am filing this because I noticed that the documentations here: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox As such I noticed that DialogResults of 10, and 11 are possible.

Describe the solution you’d like and alternatives you’ve considered

Currently I have no other alternatives in mind other than adding the 2 members to DialogResult. Also might need to add MB_CANCELTRYCONTINUE to the button options too for Cancel, Try Again, and Continue buttons (I can file a separate issue for this one). It also seems to miss on the default buttons to also be able to make button 4 the default if they wanted to as well (I can file a separate issue for this one as well). Nowever I would logically only make it available in .NET 6+ if approved.

Will this feature affect UI controls?

I do not think it will affect them at all, it will instead allow one to handle if one pressed the continue button on a dialog or try again to do specific things for those specific results which could be seen as an enhancement.

API Changes:

namespace System.Windows.Forms
{
    public enum DialogResult
    {
-        OK = 1,
+        OK = (int)ID.OK,
        // docs stay the same.
-        Cancel = 2,
+        Cancel = (int)ID.CANCEL,
        // docs stay the same.
-        Abort = 3,
+        Abort = (int)ID.ABORT,
        // docs stay the same.
-        Retry = 4,
+        Retry = (int)ID.RETRY,
        // docs stay the same.
-        Ignore = 5,
+        Ignore = (int)ID.IGNORE,
        // docs stay the same.
-        Yes = 6,
+        Yes = (int)ID.YES,
        // docs stay the same.
-        No = 7,
+        No = (int)ID.NO,
+
+        /// <summary>
+        /// The dialog box return value is Try Again (usually sent from a button labeled Try Again).
+        /// </summary>
+        TryAgain = (int)ID.TRYAGAIN,
+
+        /// <summary>
+        /// The dialog box return value is Continue (usually sent from a button labeled Continue).
+        /// </summary>
+        Continue = (int)ID.CONTINUE,
    }
    public enum MessageBoxButtons
    {
+        /// <summary>
+        ///  Specifies that the message box contains Cancel, Try Again, and Continue buttons.
+        ///  This field is constant.
+        /// </summary>
+        CancelTryContinue = (int)MB.CANCELTRYCONTINUE,
    }
    public enum MessageBoxDefaultButton
    {
+        /// <summary>
+        ///  Specifies that the forth button on the message box should be the
+        ///  default button.
+        /// </summary>
+        Button4 = (int)MB.DEFBUTTON4,
    }
}

As for MessageBox class this code here: https://github.com/dotnet/winforms/blob/f337d18dfcf05f9764a90895358928d6c342c4f2/src/System.Windows.Forms/src/System/Windows/Forms/MessageBox.cs#L413-L427

can be replaced with:

      try
      {
          ID mbresult = MessageBoxW(new HandleRef(owner, handle), text, caption, style);
+         return mbresult switch
+         {
+             _ => (DialogResult)mbresult,
+         };
      }
      finally
      {
          Application.EndModalMessageLoop();
          ThemingScope.Deactivate(userCookie);
          // Right after the dialog box is closed, Windows sends WM_SETFOCUS back to the previously active control
          // but since we have disabled this thread main window the message is lost. So we have to send it again after
          // we enable the main window.
          User32.SendMessageW(new HandleRef(owner, handle), User32.WM.SETFOCUS);
      }

And this could be attempted on removal: https://github.com/dotnet/winforms/blob/f337d18dfcf05f9764a90895358928d6c342c4f2/src/System.Windows.Forms/src/System/Windows/Forms/MessageBox.cs#L35-L56

Edit: Shown complete changes to the enums, The changes to the MessageBox class that would be needed for this is a WIP.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:22 (22 by maintainers)

github_iconTop GitHub Comments

3reactions
AraHaancommented, Mar 31, 2021

opened #4746.

2reactions
RussKiecommented, Apr 15, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

DialogResult Enum (System.Windows.Forms)
The dialog box return value is Cancel (usually sent from a button labeled Cancel). Continue, 11. The dialog box return value is Continue...
Read more >
Can't set DialogResult in WPF
DialogResult = true (or false) respectively, and the value does not get set. The window closes as expected, but DialogResult is still null....
Read more >
Returning a dialogresult from a devexpress form used as ...
I created a new devexpress form to show a new user message and called it as show below: Dim AgreementSigned As DialogResult ......
Read more >
Visual C# .NET Programming
Chapter 10, 'Working with Streams and Files,' shows you how to work with files-and, generally, how to serialize objects. Chapter 11, 'Messaging,' explains ......
Read more >
Final Exam Review #5.0, #5.05 and #6.0 Flashcards
Study with Quizlet and memorize flashcards containing terms like Using the code below, determine the value of intJ displayed in the MessageBox.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found