8

This is my code that I use:

MessageBox.Show("Do you want to save changes..?", "Save",
    MessageBoxButtons.YesNoCancel);

I want to change the text on message box buttons is it possible?

Toni
  • 1,555
  • 4
  • 15
  • 23
Gowri
  • 209
  • 1
  • 4
  • 12
  • 1
    http://www.codeproject.com/Articles/18399/Localizing-System-MessageBox – alexn Oct 03 '12 at 07:47
  • 1
    Maybe this will help you: [http://www.codeproject.com/Articles/18399/Localizing-System-MessageBox](http://www.codeproject.com/Articles/18399/Localizing-System-MessageBox) – SergioMSCosta Oct 03 '12 at 07:47

2 Answers2

8

As far as I am aware there is no way to change the default text on a MessageBox popup.

The easiest thing for you to do would be to create a simple form with a label and a couple of buttons. Here is a simple example you can use to drop into your code. You can customize the form as you wish.

public class CustomMessageBox:System.Windows.Forms.Form
{
    Label message = new Label();
    Button b1 = new Button();
    Button b2 = new Button();

    public CustomMessageBox()
    {

    }

    public CustomMessageBox(string title, string body, string button1, string button2)
    {
        this.ClientSize = new System.Drawing.Size(490, 150);
        this.Text = title;

        b1.Location = new System.Drawing.Point(411, 112);
        b1.Size = new System.Drawing.Size(75, 23);
        b1.Text = button1;
        b1.BackColor = Control.DefaultBackColor;

        b2.Location = new System.Drawing.Point(311, 112);
        b2.Size = new System.Drawing.Size(75, 23);
        b2.Text = button2; 
        b2.BackColor = Control.DefaultBackColor;

        message.Location = new System.Drawing.Point(10, 10);
        message.Text = body;
        message.Font = Control.DefaultFont;
        message.AutoSize = true;

        this.BackColor = Color.White;
        this.ShowIcon = false;

        this.Controls.Add(b1);
        this.Controls.Add(b2);
        this.Controls.Add(message);
    }        
}

You can then call this from wherever you need to like this:

        CustomMessageBox customMessage = new CustomMessageBox(
            "Warning",
            "Are you sure you want to exit without saving?",
            "Yeah Sure!",
            "No Way!" 
            );
        customMessage.StartPosition = FormStartPosition.CenterParent;
        customMessage.ShowDialog();
James Miller
  • 81
  • 1
  • 5
0

I think the MessageBox is a Win32 API beast, which means it is outside the realm of .NET. It is therefore oblivious to customization / localization. So you need to roll-your-own messagebox like James Miller suggests.

Why MS decided not to put at .NET-enabled messagebox in Forms is beyond me...

S.C. Madsen
  • 5,100
  • 5
  • 32
  • 50
  • 1
    [Task dialogs](https://msdn.microsoft.com/en-us/library/windows/desktop/bb787471%28v=vs.85%29.aspx) are meant to supersede message boxes. – Dialecticus Jan 27 '15 at 09:47