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.
Asked
Active
Viewed 565 times
2 Answers
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
-
I need a code for c# and not VB.NET – Shaivya Sharma Dec 23 '13 at 11:52
-
@ShaivyaSharma Find the edits.I have edited answer. – lokendra jayaswal Dec 23 '13 at 12:50
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