MessageBox buttons - set language?
Asked Answered
G

4

25

When you use MessageBox.Show() you have a selection of MessageBoxButtons to choose from. The buttons available are an enum, and give you options like "Yes No", "OK Cancel", etc.

When I am using, for instance, Norwegian message text the user still gets the English "Yes No".

Is there a way to change the text of the buttons (in C#) so that the language is correct? Can I override the text, or set the current locale in some way so that I can have "Ja Nei" instead of "Yes No"?

I do not want to rely on installing a .NET language pack at my client.

Guilbert answered 30/5, 2009 at 22:18 Comment(0)
S
25

There is no native support for this in .NET (as far as I know, anyway; please correct me if I'm wrong, anyone). I did come across this CodeProject article, that seem to do the trick with some message hooking and P/Invoke: http://www.codeproject.com/KB/miscctrl/Localizing_MessageBox.aspx

Sympathy answered 30/5, 2009 at 22:28 Comment(0)
G
16

Usually messagebox buttons (as all of Windows) honor the currently set UI language for Windows. So if you've got an English installation and can't change languages (MUI versions or Ultimate for Vista/7) you're out of luck.

You could implement a messagebox yourself but I'd beg you not to. Simple things like common hotkeys for the buttons, having the ability to use Ctrl+Ins to copy the contents, etc. are the ones I miss the most when people start reinventing square wheels.

Gymnasiast answered 30/5, 2009 at 22:29 Comment(0)
D
1

I don't think it is possible, but refer to the MSDN article MessageBox.Show Method. You may get some ideas. You can change the text in the message box. What about creating your own message box (new form) and displaying them?

Dealt answered 30/5, 2009 at 22:29 Comment(0)
D
0

You can create a panel (pnlExitMode), with property Visible=false, and put info text as well as buttons (btnYes, btnNo) labeled YES and NO (with button captions in "your" language) onto this panel, then place required Yes/No- actions into the button event handling routines. At decision time (in my case: warning if ini file not yet written when closing application) set panel to Visible. Panel with buttons will pop up.

Example code:

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    if (bIniModified) 
    {
        pnlExitMode.Visible = true; pnlExitMode.BringToFront();
        e.Cancel = true;
    }
}
private void btnYes_Click(object sender, EventArgs e)
{
    SaveToIni();
    pnlExitMode.Visible = false; bIniModified = false;
    Application.Exit();
}
private void btnNo_Click(object sender, EventArgs e)
{
    pnlExitMode.Visible = false; bIniModified = false;
    Application.Exit();
}
Digress answered 12/11, 2019 at 15:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.