frmMsgInfo.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Media;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace CarMonitor
  13. {
  14. public partial class frmMsgInfo : Form
  15. {
  16. private static frmMsgInfo frm = null;
  17. private static frmMonitor frmP;
  18. public static frmMsgInfo CreateInstrance(frmMonitor frmMonitoring)
  19. {
  20. if (frm == null)
  21. {
  22. frm = new frmMsgInfo();
  23. }
  24. frmP = frmMonitoring;
  25. return frm;
  26. }
  27. public frmMsgInfo()
  28. {
  29. InitializeComponent();
  30. }
  31. string rk_CurPath = Application.StartupPath; //System.Environment.CurrentDirectory;//获取到当前路径
  32. SoundPlayer play_ls = null;
  33. public void setLbTxt(string pointName)
  34. {
  35. lbPoint.Text = pointName;
  36. }
  37. private void frmMsgInfo_Load(object sender, EventArgs e)
  38. {
  39. try
  40. {
  41. play_ls = new SoundPlayer(rk_CurPath + "\\Sound\\7887.wav");
  42. }
  43. catch (Exception ex) { }
  44. finally
  45. {
  46. timer1.Start();
  47. }
  48. }
  49. private void timer1_Tick(object sender, EventArgs e)
  50. {
  51. play_ls.Play();
  52. }
  53. private void frmMsgInfo_FormClosing(object sender, FormClosingEventArgs e)
  54. {
  55. try
  56. {
  57. if (play_ls != null)
  58. {
  59. play_ls.Stop();
  60. }
  61. }
  62. catch (Exception ex) { }
  63. finally
  64. {
  65. frmP.bMsgOpen = false;
  66. frm = null;
  67. timer1.Stop();
  68. PbCacheMonitor.frmMsgClosingTime = DateTime.Now;
  69. }
  70. }
  71. public void CloseFrm()
  72. {
  73. this.Close();
  74. }
  75. public void setFrmNull()
  76. {
  77. setFormInfo(frm);
  78. }
  79. public void setFormInfo(Form fm)
  80. {
  81. setFormMsg(fm);
  82. }
  83. /// <summary>
  84. /// 如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable 3为check
  85. /// </summary>
  86. /// <param name="control"></param>
  87. /// <param name="ResultMessage"></param>
  88. /// <param name="sType"></param>
  89. private void setFormMsg(Form fm)
  90. {
  91. if (fm.InvokeRequired)
  92. {
  93. Action<Form> action = new Action<Form>(setFormInfo);
  94. Invoke(action, new object[] { fm });
  95. }
  96. else
  97. {
  98. fm.Close();
  99. }
  100. }
  101. protected override void OnVisibleChanged(EventArgs e)
  102. {
  103. base.OnVisibleChanged(e);
  104. if (!IsHandleCreated)
  105. {
  106. this.Close();
  107. }
  108. }
  109. }
  110. }