HeaderPane
Main
Hide
Share Link
Print

Message Box

SftMessageBox shows a message box in the mode of the application's SftStyle component: light, dark or with the colors of the Windows contrast theme. The Windows message box, which the Windows Forms MessageBox class shows, is always light.

The SftMessageBox.Show method has every overload of MessageBox.Show and takes the same arguments: the text, the caption, the MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton and MessageBoxOptions values, the Help button and the help file arguments. It returns the same DialogResult values. An application changes its message boxes by replacing the class name:

C#

if (SftMessageBox.Show(this, "Save the changes to the order?", "Orders",
        MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
    SaveOrder();

VB

If SftMessageBox.Show(Me, "Save the changes to the order?", "Orders",
        MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) = DialogResult.Yes Then
    SaveOrder()
End If

Behavior

The message box is laid out like the message box of Windows 11: the icon and the text in a content area, the buttons in a strip below it. It shows the stock icons of Windows and plays their sounds, and behaves as the Windows message box does:

  • Without an owner, the message box is owned by the active form of the application.
  • The default button (MessageBoxDefaultButton) has the focus when the box opens.
  • Esc and the close button close the box only when it has a Cancel button, or only an OK button; the result is then Cancel, or OK for the OK-only box. A Yes/No box can't be closed without an answer.
  • Ctrl+C and Ctrl+Insert copy the caption, the text and the button texts to the clipboard in the format of the Windows message box.
  • MessageBoxOptions.RightAlign aligns the text at the right; MessageBoxOptions.RtlReading lays the box out from right to left.
  • The Help button raises the HelpRequested event of the owner. With the overloads that take a help file, the Help button and F1 open that file.

MessageBoxOptions.DefaultDesktopOnly and MessageBoxOptions.ServiceNotification show the Windows message box instead, without an owner and without the Help button, since such a message box appears on a desktop the application's windows are not on.

MessageBoxButtons.CancelTryContinue

MessageBoxButtons.CancelTryContinue and the results DialogResult.TryAgain and DialogResult.Continue exist in .NET 10 (or later) only. On the .NET Framework the message box accepts the value 6 for these buttons and returns the values 10 (Try Again) and 11 (Continue).

The Mode of the Message Box

The message box uses the mode of the application's SftStyle component (SftStyle.DarkModeActive and SftStyle.HighContrastActive). An application without an SftStyle component gets a message box that follows the Windows light/dark setting and contrast theme, but every application that uses SftStyle/NET has an SftStyle component, which carries the license the message box needs (see Licensing and Contents).