-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Labels
api-suggestion(1) Early API idea and discussion, it is NOT ready for implementation(1) Early API idea and discussion, it is NOT ready for implementation
Description
Background and motivation
Improving MessageBox is something every developer wants, so they all resort to creating an alternative interface for it. You can find many examples on Github. This is because they cannot localize it or change its appearance, so this new API solves this problem.
API Proposal
namespace System.Windows.Forms;
public class MessageBox
{
/// <summary>
/// Type of <see cref="Resources"/> that used to localize Buttons in <see cref="System.Windows.Forms.MessageBox"/>.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static Type? ResourceType { get; set; }
/// <summary>
/// The foreground color of the <see cref="System.Windows.Forms.MessageBox"/>.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static Color ForeColor { get; set; } = SystemColors.ControlText;
/// <summary>
/// The background color of the <see cref="System.Windows.Forms.MessageBox"/>.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static Color BackColor { get; set; } = SystemColors.Window;
/// <summary>
/// The background color of the Footer in <see cref="System.Windows.Forms.MessageBox"/>.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static Color FooterBackColor { get; set; } = SystemColors.Control;
/// <summary>
/// Sets or gets the MessageBox BorderRadius.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public MessageBoxCornerPreference MessageBoxBorderRadius{ get;set;}
/// <summary>
/// Sets or gets the MessageBox's border color.
/// </summary>
public Color MessageBoxBorderColor{ get;set;}
/// <summary>
/// Sets or gets the MessageBox's title bar back color (caption back color).
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public Color MessageBoxCaptionColor{ get;set;}
/// <summary>
/// Sets or gets the MessageBox's title bar text color.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public Color MessageBoxCaptionTextColor{ get;set;}
}
API Usage
MessageBox.ResourceType = typeof(Properties.Resources)
MessageBox.ForeColor = SystemColors.ControlText;
MessageBox.BackColor = SystemColors.Window;
MessageBox.FooterBackColor = SystemColors.Control;
MessageBox.Show("MessageBox with Custom Icon", "Custom Icon", MessageBoxButtons.YesNo, SystemIcons.GetStockIcon(StockIconId.Users, StockIconOptions.ShellIconSize));
Alternative Designs
/// <summary>
/// Displays a message box with specified text, caption, style, and custom Icon. with Help Button.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static DialogResult Show(
string? text,
string? caption,
MessageBoxButtons buttons,
Icon icon,
MessageBoxDefaultButton defaultButton,
MessageBoxOptions options,
bool displayHelpButton)
{
s_customIcon = icon;
return ShowCore(null, text, caption, buttons, MessageBoxIcon.Information, defaultButton, options, displayHelpButton);
}
/// <summary>
/// Displays a message box with specified text, caption, style, Help file Path, and custom Icon.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static DialogResult Show(
string? text,
string? caption,
MessageBoxButtons buttons,
Icon icon,
MessageBoxDefaultButton defaultButton,
MessageBoxOptions options,
string helpFilePath)
{
HelpInfo hpi = new(helpFilePath);
s_customIcon = icon;
return ShowCore(null, text, caption, buttons, MessageBoxIcon.Information, defaultButton, options, hpi);
}
/// <summary>
/// Displays a message box with specified text, caption, style, Help file Path, and custom Icon. for a IWin32Window.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static DialogResult Show(
IWin32Window? owner,
string? text,
string? caption,
MessageBoxButtons buttons,
Icon icon,
MessageBoxDefaultButton defaultButton,
MessageBoxOptions options,
string helpFilePath)
{
HelpInfo hpi = new(helpFilePath);
s_customIcon = icon;
return ShowCore(owner, text, caption, buttons, MessageBoxIcon.Information, defaultButton, options, hpi);
}
/// <summary>
/// Displays a message box with specified text, caption, style, Help file Path, keyword, and custom Icon.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static DialogResult Show(
string? text,
string? caption,
MessageBoxButtons buttons,
Icon icon,
MessageBoxDefaultButton defaultButton,
MessageBoxOptions options,
string helpFilePath,
string keyword)
{
HelpInfo hpi = new(helpFilePath, keyword);
s_customIcon = icon;
return ShowCore(null, text, caption, buttons, MessageBoxIcon.Information, defaultButton, options, hpi);
}
/// <summary>
/// Displays a message box with specified text, caption, style, Help file Path, keyword, and custom Icon for a IWin32Window.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static DialogResult Show(
IWin32Window? owner,
string? text,
string? caption,
MessageBoxButtons buttons,
Icon icon,
MessageBoxDefaultButton defaultButton,
MessageBoxOptions options,
string helpFilePath,
string keyword)
{
HelpInfo hpi = new(helpFilePath, keyword);
s_customIcon = icon;
return ShowCore(owner, text, caption, buttons, MessageBoxIcon.Information, defaultButton, options, hpi);
}
/// <summary>
/// Displays a message box with specified text, caption, style, Help file Path HelpNavigator, and custom Icon.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static DialogResult Show(
string? text,
string? caption,
MessageBoxButtons buttons,
Icon icon,
MessageBoxDefaultButton defaultButton,
MessageBoxOptions options,
string helpFilePath,
HelpNavigator navigator)
{
HelpInfo hpi = new(helpFilePath, navigator);
s_customIcon = icon;
return ShowCore(null, text, caption, buttons, MessageBoxIcon.Information, defaultButton, options, hpi);
}
/// <summary>
/// Displays a message box with specified text, caption, style, Help file Path HelpNavigator, and custom Icon for IWin32Window.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static DialogResult Show(
IWin32Window? owner,
string? text,
string? caption,
MessageBoxButtons buttons,
Icon icon,
MessageBoxDefaultButton defaultButton,
MessageBoxOptions options,
string helpFilePath,
HelpNavigator navigator)
{
HelpInfo hpi = new(helpFilePath, navigator);
s_customIcon = icon;
return ShowCore(owner, text, caption, buttons, MessageBoxIcon.Information, defaultButton, options, hpi);
}
/// <summary>
/// Displays a message box with specified text, caption, style, Help file Path ,HelpNavigator,object and custom Icon.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static DialogResult Show(
string? text,
string? caption,
MessageBoxButtons buttons,
Icon icon,
MessageBoxDefaultButton defaultButton,
MessageBoxOptions options,
string helpFilePath,
HelpNavigator navigator,
object? param)
{
HelpInfo hpi = new(helpFilePath, navigator, param);
s_customIcon = icon;
return ShowCore(null, text, caption, buttons, MessageBoxIcon.Information, defaultButton, options, hpi);
}
/// <summary>
/// Displays a message box with specified text, caption, style, Help file Path ,HelpNavigator, object and custom Icon for a IWin32Window.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static DialogResult Show(
IWin32Window? owner,
string? text,
string? caption,
MessageBoxButtons buttons,
Icon icon,
MessageBoxDefaultButton defaultButton,
MessageBoxOptions options,
string helpFilePath,
HelpNavigator navigator,
object? param)
{
HelpInfo hpi = new(helpFilePath, navigator, param);
s_customIcon = icon;
return ShowCore(owner, text, caption, buttons, MessageBoxIcon.Information, defaultButton, options, hpi);
}
/// <summary>
/// Displays a message box with specified text, caption, style, and custom Icon.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static DialogResult Show(
string? text,
string? caption,
MessageBoxButtons buttons,
Icon icon,
MessageBoxDefaultButton defaultButton,
MessageBoxOptions options)
{
s_customIcon = icon;
return ShowCore(null, text, caption, buttons, MessageBoxIcon.Information, defaultButton, options, false);
}
/// <summary>
/// Displays a message box with specified text, caption, style, and custom Icon.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static DialogResult Show(
string? text,
string? caption,
MessageBoxButtons buttons,
Icon icon,
MessageBoxDefaultButton defaultButton)
{
s_customIcon = icon;
return ShowCore(null, text, caption, buttons, MessageBoxIcon.Information, defaultButton, 0, false);
}
/// <summary>
/// Displays a message box with specified text, caption, style, and custom Icon.
/// </summary>
[Experimental(DiagnosticIDs.ExperimentalMessageBox, UrlFormat = DiagnosticIDs.UrlFormat)]
public static DialogResult Show(
string? text,
string? caption,
MessageBoxButtons buttons,
Icon icon)
{
s_customIcon = icon;
return ShowCore(null, text, caption, buttons, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 0, false);
}
Risks
No response
Will this feature affect UI controls?
Will VS Designer need to support the feature? no
Will this feature need to be localized or be localizable? yes
Metadata
Metadata
Assignees
Labels
api-suggestion(1) Early API idea and discussion, it is NOT ready for implementation(1) Early API idea and discussion, it is NOT ready for implementation