2012-10-03 5 views
6

これは...メッセージボックスボタンのテキストを変更するには?私はメッセージボックスのボタンのテキストを変更したい

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

私が使用私のコードですが、それは可能..です?

+1

http://www.codeproject.com/Articles/18399/Localizing-System-MessageBox – alexn

+1

多分これ意志助けてください:[http://www.codeproject.com/Articles/18399/Localizing-System-MessageBox](html/www.codeproject.com/Articles/18399/Localizing-System-MessageBox) – SergioMSCosta

答えて

7

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

あなたがするのが最も簡単なことは、ラベルと2つのボタンで簡単なフォームを作成することです。ここでは、コードにドロップするための簡単な例を示します。必要に応じてフォームをカスタマイズできます。

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(); 
0

私はメッセージボックスが、それは.NETの領域外であることを意味するのWin32 APIの獣、だと思います。したがって、カスタマイズ/ローカリゼーションは気にしません。だから、ジェームス・ミラーのようなメッセージ・ボックスをロールバックする必要があります。

MSは、フォームでの.NET対応のメッセージボックスに入れていないことを決めたのはなぜ私を超えている...

+1

[タスクダイアログ] (https://msdn.microsoft.com/en-us/library/windows/desktop/bb787471%28v=vs.85%29.aspx)は、メッセージボックスに取って代わるものです。 – Dialecticus

関連する問題