locked
looking for how to make my own MessageBox sample code RRS feed

  • Question

  • hi

    looking for how to make my own MessageBox sample code

    something simple that has title, body text and yes/no button

    and how to use it 

    thanks in advance
    Thursday, February 17, 2011 6:57 AM

Answers

  • I have already replied to similar question here. Anyways, I am putting it again here,

    public partial class CustomMessageBox : Form
    {
     private CustomMessageBox()
     {
      InitializeComponent();
     }  
    
     private static CustomMessageBox _iBox;
     public static DialogResult Show(string message)
     {
      if (_iBox == null)
      {
       _iBox = new CustomMessageBox();
      }
    
      _iBox.lblMessage.Text = message;
      _iBox.ShowInTaskbar = false;
      _iBox.FormBorderStyle = FormBorderStyle.FixedSingle;
    
      return _iBox.ShowDialog();
     }
    
     private void btnYes_Click(object sender, EventArgs e)
     {
      DialogResult = System.Windows.Forms.DialogResult.Yes;
     }
    
     private void btnNo_Click(object sender, EventArgs e)
     {
      DialogResult = System.Windows.Forms.DialogResult.No;
     }  
    }
    

     

    Now you can use this like,

    CustomMessageBox.Show( message );
    

     

     


    Please mark this post as answer if it solved your problem. Happy Programming !!!
    • Marked as answer by E_gold Sunday, February 20, 2011 7:01 AM
    Thursday, February 17, 2011 7:05 AM
  • Hi E_gold,

    You can achieve the same by creating a Form which has three button and same look as the MessageBox. You can then set the DialogResult accordingly.

        I have created such Message box having different UI having images and customized look like MessageBox having same size.

        You can then handle the DialogResult as required:

     private void btnYes_Click(object sender, EventArgs e)
      {
       this.DialogResult = DialogResult.Yes;
       this.Close();
      }
    
      private void btnNo_Click(object sender, EventArgs e)
      {
       this.DialogResult = DialogResult.No;
       this.Close();
      }
    
      private void btnCancel_Click(object sender, EventArgs e)
      {
       this.DialogResult = DialogResult.Cancel;
       this.Close();
      }

    Thanks,

    Paras Sanghani

    http://parassanghani.blogspot.com/

    Mark As Answer if it helped you.

    • Marked as answer by E_gold Sunday, February 20, 2011 7:01 AM
    Thursday, February 17, 2011 7:14 AM

All replies

  • I have already replied to similar question here. Anyways, I am putting it again here,

    public partial class CustomMessageBox : Form
    {
     private CustomMessageBox()
     {
      InitializeComponent();
     }  
    
     private static CustomMessageBox _iBox;
     public static DialogResult Show(string message)
     {
      if (_iBox == null)
      {
       _iBox = new CustomMessageBox();
      }
    
      _iBox.lblMessage.Text = message;
      _iBox.ShowInTaskbar = false;
      _iBox.FormBorderStyle = FormBorderStyle.FixedSingle;
    
      return _iBox.ShowDialog();
     }
    
     private void btnYes_Click(object sender, EventArgs e)
     {
      DialogResult = System.Windows.Forms.DialogResult.Yes;
     }
    
     private void btnNo_Click(object sender, EventArgs e)
     {
      DialogResult = System.Windows.Forms.DialogResult.No;
     }  
    }
    

     

    Now you can use this like,

    CustomMessageBox.Show( message );
    

     

     


    Please mark this post as answer if it solved your problem. Happy Programming !!!
    • Marked as answer by E_gold Sunday, February 20, 2011 7:01 AM
    Thursday, February 17, 2011 7:05 AM
  • Hi E_gold,

    You can achieve the same by creating a Form which has three button and same look as the MessageBox. You can then set the DialogResult accordingly.

        I have created such Message box having different UI having images and customized look like MessageBox having same size.

        You can then handle the DialogResult as required:

     private void btnYes_Click(object sender, EventArgs e)
      {
       this.DialogResult = DialogResult.Yes;
       this.Close();
      }
    
      private void btnNo_Click(object sender, EventArgs e)
      {
       this.DialogResult = DialogResult.No;
       this.Close();
      }
    
      private void btnCancel_Click(object sender, EventArgs e)
      {
       this.DialogResult = DialogResult.Cancel;
       this.Close();
      }

    Thanks,

    Paras Sanghani

    http://parassanghani.blogspot.com/

    Mark As Answer if it helped you.

    • Marked as answer by E_gold Sunday, February 20, 2011 7:01 AM
    Thursday, February 17, 2011 7:14 AM
  • When you do the form is  this.DialogResult = DialogResult.No; the form is automatically closed. You don't have to call Close method explicitly.


    Please mark this post as answer if it solved your problem. Happy Programming !!!
    Thursday, February 17, 2011 7:23 AM
  • Hi E_gold,

    Thank you for posting in the MSDN Forum.

    According to your description of the problem, I have some suggestions for you to perform: Creating a new form that provides the functionality what you want added in. You'll need to write the code to show the correct buttons and icons and return the correct DialogResult. In addition, there are some examples about making custom MessageBox, you can refer to the following links:

    (1) http://www.codeproject.com/KB/cs/A_Custom_Message_Box.aspx

    (2) http://www.codeproject.com/KB/cs/Custom_Message_2.aspx

    (3) http://www.codeproject.com/KB/dialog/MessageBoxEx.aspx

    I hope this will help resolve your problem. If I have misunderstood anything, please feel free to let me know.

    Best Regards,

    Mio


    Mio Miao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, February 18, 2011 11:46 AM
  • thanks !! it works !!
    Sunday, February 20, 2011 7:01 AM