2013-12-23 20 views

回答

0

您可以嘗試使用自己定製的按鈕和圖標以及要顯示的標籤製作自定義消息框。 如下創建構造函數。 添加屬性DisplayData存儲要顯示的messageBox數據。

public void CustomMessage(string title, string dataTodisplay, string leftButton, string rightButton, MessageBoxIcon iconSet) 
    { 
     // Set up some properties. 
     this.Font = SystemFonts.MessageBoxFont; 
     this.ForeColor = SystemColors.WindowText; 
     InitializeComponent(); 
     DisplayData = dataTodisplay; 
     // Do some measurements with Graphics. 
     SetFormData(dataTodisplay); 

     // Set the title, and some Text properties. 
     if (string.IsNullOrEmpty(title) == false) 
     { 
      this.Text = title; 
     } 
     // Set the left button, which is optional. 
     if (string.IsNullOrEmpty(leftButton) == false) 
     { 
      this.ButtonOK.Text = leftButton;     
     } 
     Else 
     { 
      this.AcceptButton = ButtonCancel 
      this.ButtonCancel.Visible = False 
     } 
     // Set the PictureBox and the icon. 
     if ((iconSet != null)) 
     { 
      ShowMessageBoxIcon(iconSet); 
     } 

分配圖標到圖片框這裏

private void ShowMessageBoxIcon(MessageBoxIcon iconSet) 
    { 
     switch (iconSet) 
     { 
      case MessageBoxIcon.Asterisk: 
       PictureBoxIconImage.Image = Bitmap.FromHicon(SystemIcons.Asterisk.Handle); 
       break; 
      case MessageBoxIcon.Error: 
       PictureBoxIconImage.Image = Bitmap.FromHicon(SystemIcons.Error.Handle); 
      /* 
      * Add remaining icons here 
      * 
      */ 
     } 
     } 
     this.ButtonCancel.Text = rightButton 
     } 
+0

我需要爲C#和代碼不VB.NET –

+0

@ShaivyaSharma找到edits.I已編輯答案。 –

0

創建自己的對話框,並把按鈕。您可以爲按鈕分配對話結果值。

this.button1.DialogResult = System.Windows.Forms.DialogResult.OK; 
this.button2.DialogResult = System.Windows.Forms.DialogResult.No;