Share via


BaseForm.ShowMessage Method

Definition

Displays a message box that uses the specified text.

Overloads

ShowMessage(String)

Displays a message box that uses the specified text.

ShowMessage(String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)

Displays a message box that uses the specified text, button set, symbol, and default button.

ShowMessage(String)

Displays a message box that uses the specified text.

protected public:
 void ShowMessage(System::String ^ message);
protected internal void ShowMessage (string message);
member this.ShowMessage : string -> unit
Protected Friend Sub ShowMessage (message As String)

Parameters

message
String

The message to display.

Examples

The following example saves the window geometry to the preference store. If the preference service is null, a message is displayed.

void persistWindowVals() {

    IPreferencesService prefService = (IPreferencesService)
            GetService(typeof(IPreferencesService));

    if (prefService == null) {
        ShowMessage("Null PreferencesService");
        return;
    }

    if (prefService != null) {
        PreferencesStore prefStore = prefService.GetPreferencesStore(
            new Guid(PreferenceKey));

        if (WindowState == FormWindowState.Maximized) {
            prefStore.SetValue(MaximizedPreferenceKey, true, false);
        } else if (WindowState != FormWindowState.Minimized) {
            prefStore.SetValue(WidthPreferenceKey, Size.Width, -1);
            prefStore.SetValue(HeightPreferenceKey, Size.Height, -1);
            prefStore.SetValue(YPosPreferenceKey, Location.Y, -1);
            prefStore.SetValue(XPosPreferenceKey, Location.X, -1);
            prefStore.SetValue(MaximizedPreferenceKey, false, false);
        }
    }
}

Applies to

ShowMessage(String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)

Displays a message box that uses the specified text, button set, symbol, and default button.

protected public:
 System::Windows::Forms::DialogResult ShowMessage(System::String ^ message, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton);
protected internal System.Windows.Forms.DialogResult ShowMessage (string message, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton);
member this.ShowMessage : string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton -> System.Windows.Forms.DialogResult
Protected Friend Function ShowMessage (message As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton) As DialogResult

Parameters

message
String

The message to display.

buttons
MessageBoxButtons

One of the MessageBoxButtons values.

icon
MessageBoxIcon

One of the MessageBoxIcon values.

defaultButton
MessageBoxDefaultButton

One of the MessageBoxDefaultButton values.

Returns

One of the DialogResult values.

Examples

The following example prompts the user to save changes.

protected override void OnFormClosing(FormClosingEventArgs e) {

    base.OnFormClosing(e);

    CloseReason reason = e.CloseReason;
    if (reason != CloseReason.UserClosing &&
        reason != CloseReason.ApplicationExitCall)
        return;

    IServiceProvider serviceProvider = this.ServiceProvider;

    if (serviceProvider == null)
        return;

    IConnectionManager connectionManager = (IConnectionManager)
        GetService(typeof(IConnectionManager));

    if ((connectionManager == null) ||
        (!connectionManager.IsDirty))   // nothing to save
        return;

    DialogResult result = ShowMessage(
        "The connection list has changed. Save changes?",
        MessageBoxButtons.YesNoCancel,  // button set
        MessageBoxIcon.Question,         // Icon
        MessageBoxDefaultButton.Button1); // Default btn

    if (result == DialogResult.Yes) {
        connectionManager.Save();
    } else if (result == DialogResult.Cancel) {
        e.Cancel = true;
    }

} 

Applies to