1, the Winfrom project often uses the message prompt, Generally use the MessageBox.Show method, but like the error prompt, ask a hint, the warning hint is a bit complicated to write, and the following several hints have icons, but MessageBox.Show no icon, will affect the consistency of the project. So it encapsulates a common message prompt class Messagecommon
Public Static classMessagecommon {/// <summary> ///pop-up cue box by type/// </summary> /// <param name= "type" >type war: Warning Que: asking err: Error Other default is message prompt</param> /// <param name= "MSG" >message</param> Public StaticDialogResult Showmassage (stringTypestringmsg) { Switch(type) { Case "War": returnMessageBox.Show (MSG,"Warning!", MessageBoxButtons.OK, messageboxicon.warning); Case "que": returnMessageBox.Show (MSG,"do you want to continue?", Messageboxbuttons.okcancel, messageboxicon.question); Case "Err": returnMessageBox.Show (MSG,"Error!", MessageBoxButtons.OK, Messageboxicon.error); default: returnMessageBox.Show (MSG,"Tips!", MessageBoxButtons.OK, messageboxicon.information); } } /// <summary> ///warning Prompt/// </summary> /// <param name= "MSG" >Message Content</param> /// <returns></returns> Public StaticDialogResult Showwar (stringmsg) { returnShowmassage ("War", MSG); } /// <summary> ///Ask a hint/// </summary> /// <param name= "MSG" >Message Content</param> /// <returns>DialogResult.OK or DialogResult.Cancel</returns> Public StaticDialogResult Showque (stringmsg) { returnShowmassage ("que", MSG); } /// <summary> ///Error Hints/// </summary> /// <param name= "MSG" >Message Content</param> /// <returns></returns> Public StaticDialogResult Showerr (stringmsg) { returnShowmassage ("Err", MSG); } /// <summary> ///General Tips/// </summary> /// <param name= "MSG" >Message Content</param> /// <returns></returns> Public StaticDialogResult Showinf (stringmsg) { returnShowmassage ("inf", MSG); } }
2. The following methods are used:
//General Tips Private voidButton1_Click (Objectsender, EventArgs e) {Messagecommon.showinf ("Tips!"); } //Error Hints Private voidButton2_Click (Objectsender, EventArgs e) {Messagecommon.showerr ("wrong operation!"); } //warning Prompt Private voidButton3_Click (Objectsender, EventArgs e) {Messagecommon.showwar ("No action!"); } //Ask a hint Private voidButton4_Click (Objectsender, EventArgs e) { if(Messagecommon.showque ("does the operation have a risk of continuing?")==DialogResult.OK) {Messagecommon.showinf ("Determine"); } Else{Messagecommon.showinf ("Cancel"); } }
3. Operation:
4. Sample code:
http://download.csdn.net/detail/kehaigang29/8832703
WINFROM Hint message box public class