Windows with the message box is ugly, especially to go to WIN7 under more, the project used in the message box is very much, basically has the hint information, the error message, inquires the information these three kinds, from the esthetic angle, MessageBox.Show () This method comes out the message box to be somewhat unsatisfactory, So I wrote one myself and felt more comfortable with myself.
Description: The following naming ignores case.
Custom Info Box
System Information Box
Customize the Query box
System Inquiry Box
Step 1:
Create a new form Frmmessagebox, place a PictureBox (Picico) control and a label (Labinfo) control and two panel controls, where a button is placed in the Panel1, named Btnok, and the Text property is determined ( &o), the DialogResult property is set to OK, In this case, the end of the dialog will return to DialogResult.OK, here in order to be able to adapt to the length of the message to change the width of the button and the width of the dialog box, deliberately put two panel, the other panel placed two buttons, one is, a No.
In this way, I believe you already know the use of these controls, picture frame used to display the corresponding picture, information box is a big tick, ask box is a big question mark, in advance to add resources to the project, the proposed picture file name best info.png/ Error.png such, the time to take resources to find good, label used to display messages.
Step 2:
Define enumerated types, there are three of them defined here, and you can add them yourself.
public enum Messageboxstyle
{
Info=0,
Question=1,
error=2
};
Step 3:
overriding constructors
Public Frmmessagebox (Messageboxstyle messageboxstyle,string msg)
{
InitializeComponent ();
if (Messageboxstyle = = Messageboxstyle.info)
{
Picico.image = Global::myalarmsystem.properties.resources.info;
This. Text = "hint";
Panel1. Visible = true;
Panel2. Visible = false;
}
else if (Messageboxstyle = = messageboxstyle.question)
{
Picico.image = global::myalarmsystem.properties.resources.question;
This. Text = "inquiry";
Panel1. Visible = false;
Panel2. Visible = true;
}
else if (Messageboxstyle = = Messageboxstyle.error)
{
Picico.image = Global::myalarmsystem.properties.resources.error;
This. Text = "Error";
Panel1. Visible = true;
Panel2. Visible = false;
}
This.labInfo.Text = msg;
SizeF size = Textrenderer.measuretext (msg, New Font ("XXFarEastFont-Arial", fontstyle.regular));
int tempwidth = (int) size. Width;
if (tempwidth <= 249) {return;}
This. Width = (int) size. Width + 130;
This.panel1.Width = TempWidth-20;
This.panel2.Width = TempWidth-20;
Btnyes.width = TEMPWIDTH/2-20;
Btnno.width = TEMPWIDTH/2-20;
}