[DialogResult] Add TryAgain and Continue (result 10, and 11) respectively.
See original GitHub issueIs 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:
- Created 2 years ago
- Reactions:3
- Comments:22 (22 by maintainers)
opened #4746.
@terrajobst no, false alarm. More details here https://github.com/dotnet/winforms/pull/4746#issuecomment-819997698