MessageBox is often used in programs.
MessageBox. Show () contains a total of 21 overload methods. The common usage is summarized as follows:
1. MessageBox. Show ("Hello ~~~~ ");
The simplest way is to display only the prompt information.
2. MessageBox. Show ("There are something wrong! "," ERROR ");
You can add a title to the message box.
3. if (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel) = DialogResult. OK)
{
// Delete
}
This is used when you ask whether to delete it.
4. if (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel, MessageBoxIcon. Question) = DialogResult. OK)
{
// Delete
}
You can add an Icon to MessageBox. net provides common options for icons.
5. if (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel, MessageBoxIcon. Question, MessageBoxDefaultButton. Button2) = DialogResult. OK)
{
// Delete
}
The default focus of MessageBox can be changed as follows:
6. if (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel, MessageBoxIcon. Question, MessageBoxDefaultButton. Button2, MessageBoxOptions. RtlReading) = DialogResult. OK)
{
// Delete
}
Reverse display:
7. if (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel, MessageBoxIcon. Question, MessageBoxDefaultButton. Button2, MessageBoxOptions. RightAlign, true) = DialogResult. OK)
{
// Delete
}
Add the Help button:
8. if (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel, MessageBoxIcon. Question, queue. Button1, MessageBoxOptions. RtlReading, @"/folder/file.htm ") = DialogResult. OK)
{
// Delete
}
Specify the path of the Help file and click it to open the Help file under this path.
9. // HelpNavigator specifies a constant to indicate the Help File element to be displayed. The Find help file is displayed on the search page.
If (MessageBox. Show ("Delete this user? "," Confirm Message ", MessageBoxButtons. OKCancel, MessageBoxIcon. question, MessageBoxDefaultButton. button1, MessageBoxOptions. rtlReading, @ "/folder/file.htm", HelpNavigator. find) = DialogResult. OK)
{
// Delete
}