MessageBoxUtil.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Windows.Forms;
  2. namespace Update.Util
  3. {
  4. /// <summary>
  5. /// 对话框工具
  6. /// </summary>
  7. public static class MessageBoxUtil
  8. {
  9. //主窗口
  10. private static Form MainForm
  11. {
  12. get
  13. {
  14. FormCollection openForms = Application.OpenForms;
  15. return openForms.Count == 0 ? null : openForms[0];
  16. }
  17. }
  18. /// <summary>
  19. /// 显示提示对话框
  20. /// </summary>
  21. /// <param name="text"></param>
  22. /// <returns></returns>
  23. public static DialogResult Info(string text)
  24. {
  25. return MessageBox.Show(MainForm, text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  26. }
  27. /// <summary>
  28. /// 显示警告对话框
  29. /// </summary>
  30. /// <param name="text"></param>
  31. /// <returns></returns>
  32. public static DialogResult Warn(string text)
  33. {
  34. return MessageBox.Show(MainForm, text, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  35. }
  36. /// <summary>
  37. /// 显示错误对话框
  38. /// </summary>
  39. /// <param name="text"></param>
  40. /// <returns></returns>
  41. public static DialogResult Error(string text)
  42. {
  43. return MessageBox.Show(MainForm, text, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  44. }
  45. /// <summary>
  46. /// 显示确认对话框
  47. /// </summary>
  48. /// <param name="text"></param>
  49. /// <returns></returns>
  50. public static DialogResult Confirm(string text)
  51. {
  52. return MessageBox.Show(MainForm, text, "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  53. }
  54. }
  55. }