0

I wan to create a DialogResult MessageBox with my own specified labels on the buttons. I am aware of coding DR MessageBox with YesNo option buttons.

Shaivya Sharma
  • 137
  • 1
  • 3
  • 14

2 Answers2

0

You can try making custom message Box with your own customized buttons and icons and Label that you want to display. Create Constructor as below. Add property DisplayData to store messageBox Data To Display.

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

Assign Icons to picturebox here

 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
      }
lokendra jayaswal
  • 298
  • 1
  • 6
  • 19
0

Create your own dialog and put buttons. You can assign dialog result values for buttons.

this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
this.button2.DialogResult = System.Windows.Forms.DialogResult.No;
Sampath
  • 1,173
  • 18
  • 29