MessageBoxCustom.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. namespace LYFZ
  7. {
  8. public class ItemValue
  9. {
  10. private string _text = string.Empty;
  11. public string Text
  12. {
  13. get
  14. {
  15. if (this._text != null)
  16. {
  17. return this._text;
  18. }
  19. return string.Empty;
  20. }
  21. set { _text = value; }
  22. }
  23. private object _value = string.Empty;
  24. public object Value
  25. {
  26. get { return this._value; }
  27. set { this._value = value; }
  28. }
  29. /// <summary>
  30. ///
  31. /// </summary>
  32. /// <param name="_value"></param>
  33. /// <param name="_text"></param>
  34. public ItemValue(object value, string text)
  35. {
  36. this._value = value;
  37. this._text = text;
  38. }
  39. object _tag;
  40. /// <summary>
  41. ///
  42. /// </summary>
  43. public object Tag
  44. {
  45. get { return _tag; }
  46. set { _tag = value; }
  47. }
  48. public override string ToString()
  49. {
  50. return this._text;
  51. }
  52. }
  53. /// <summary>
  54. /// 自定义弹窗,显示可包含文本、按钮和符号(通知并指示用户)的消息框。
  55. /// </summary>
  56. public class MessageBoxCustom
  57. { /// <summary>
  58. /// 弹出消息框
  59. /// </summary>
  60. /// <param name="msg">要显示的消息</param>
  61. /// <param name="title">标题 可以省略</param>
  62. /// <returns></returns>
  63. public static DialogResult Show(string msg, string title = "提示消息!", MessageBoxButtons msgBoxButton = MessageBoxButtons.OK, System.ComponentModel.BackgroundWorker backgroundWorker=null,bool isTop=false)
  64. {
  65. try
  66. {
  67. if (backgroundWorker != null)
  68. {
  69. backgroundWorker.ReportProgress(-1);
  70. }
  71. }
  72. catch {
  73. backgroundWorker.Dispose();
  74. backgroundWorker = null;
  75. }
  76. LYFZ.ComponentLibrary.frmMessageBox msgBox = new LYFZ.ComponentLibrary.frmMessageBox();
  77. msgBox.IsLoginValidation = false;
  78. msgBox.Text = title;
  79. msgBox.lbMseValue.Text = msg;
  80. msgBox.TopMost = isTop;
  81. msgBox.MsgBoxButtons = msgBoxButton;
  82. DialogResult dialogResult=msgBox.ShowDialog();
  83. try
  84. {
  85. if (backgroundWorker != null)
  86. {
  87. backgroundWorker.ReportProgress(0);
  88. }
  89. }
  90. catch { }
  91. return dialogResult; //msgBox.DialogResult;
  92. }
  93. }
  94. }