8

これは私が使用する私のコードです:

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

メッセージボックスのボタンのテキストを変更したいのですが可能ですか?

4

2 に答える 2

8

私の知る限り、MessageBox ポップアップのデフォルト テキストを変更する方法はありません。

最も簡単な方法は、ラベルといくつかのボタンを備えた単純なフォームを作成することです。これは、コードにドロップするために使用できる簡単な例です。必要に応じてフォームをカスタマイズできます。

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);
    }        
}

次に、これを好きな場所から呼び出すことができます。

        CustomMessageBox customMessage = new CustomMessageBox(
            "Warning",
            "Are you sure you want to exit without saving?",
            "Yeah Sure!",
            "No Way!" 
            );
        customMessage.StartPosition = FormStartPosition.CenterParent;
        customMessage.ShowDialog();
于 2015-01-26T16:36:41.683 に答える
0

MessageBox は Win32 API ビーストだと思います。つまり、.NET の領域外にあるということです。したがって、カスタマイズ/ローカリゼーションを無視しています。したがって、James Miller が提案するように、独自のメッセージ ボックスを作成する必要があります。

MS が Forms で .NET 対応のメッセージボックスを配置しないことにした理由は、私には理解できません...

于 2015-01-27T09:34:15.033 に答える