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 팝업에서 기본 텍스트를 변경할 방법이 없습니다.

가장 쉬운 방법은 레이블과 몇 개의 버튼이있는 간단한 양식을 만드는 것입니다. 다음은 코드에 삽입 할 수있는 간단한 예제입니다. 원하는대로 양식을 사용자 정의 할 수 있습니다.

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 짐승,라고 생각합니다. 그러므로 커스터마이징/로컬 리 제이션은 잊어 버릴 수 있습니다. 따라서 제임스 밀러 (James Miller)와 같은 자신 만의 메시지 상자가 필요합니다. MS는 양식에서 .NET 기반 메시지 박스에 넣어하지 않기로 결정 나를 넘어 왜

...

+1

[작업 대화 상자] (https://msdn.microsoft.com/en-us/library/windows/desktop/bb787471%28v=vs.85%29.aspx)는 메시지 상자를 대체하기위한 것입니다. – Dialecticus

관련 문제