RichTextAutoBottom.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. using System;
  2. using System.Drawing;
  3. using System.Media;
  4. using System.Threading;
  5. using System.Windows.Forms;
  6. using UAS_MES_NEW.PublicMethod;
  7. namespace UAS_MES_NEW.CustomControl.RichText
  8. {
  9. public partial class RichTextAutoBottom : RichTextBox
  10. {
  11. Thread thread;
  12. string FileName = "";
  13. public RichTextAutoBottom()
  14. {
  15. InitializeComponent();
  16. thread = new Thread(PlaySound);
  17. TextChanged += RichTextBox_TextChange;
  18. }
  19. private void RichTextBox_TextChange(object sender, EventArgs e)
  20. {
  21. SelectionStart = Text.Length;
  22. ScrollToCaret();
  23. }
  24. /// <summary>
  25. /// color设置AppendText的颜色
  26. /// </summary>
  27. /// <param name="str"></param>
  28. /// <param name="color"></param>
  29. public void AppendText(string str, Color color)
  30. {
  31. SelectionColor = color;
  32. base.AppendText(str);
  33. //如果颜色是红色则进行提示音
  34. if (color == Color.Red && Entity.SystemInf.CheckAudioEnable)
  35. {
  36. FileName = Application.StartupPath + @"\Resources\Sound\FAIL.wav";
  37. thread.Start();
  38. thread = new Thread(PlaySound);
  39. }
  40. else if (color == Color.Green && Entity.SystemInf.CheckAudioEnable)
  41. {
  42. //颜色是绿色,进行正确提示音
  43. FileName = Application.StartupPath + @"\Resources\Sound\PASS.wav";
  44. thread.Start();
  45. thread = new Thread(PlaySound);
  46. }
  47. else if (color == Color.Blue && Entity.SystemInf.CheckAudioEnable)
  48. {
  49. //颜色是绿色,进行正确提示音
  50. FileName = Application.StartupPath + @"\Resources\Sound\4082.wav";
  51. thread.Start();
  52. thread = new Thread(PlaySound);
  53. }
  54. else if (color == Color.OrangeRed && Entity.SystemInf.CheckAudioEnable)
  55. {
  56. //颜色是绿色,进行正确提示音
  57. FileName = Application.StartupPath + @"\Resources\Sound\失败.wav";
  58. thread.Start();
  59. thread = new Thread(PlaySound);
  60. }
  61. LogManager.DoLog(FindForm().Tag + str);
  62. }
  63. /// <summary>
  64. /// 提示错误信息清楚指定控件的值
  65. /// </summary>
  66. /// <param name="str"></param>
  67. /// <param name="color"></param>
  68. /// <param name="ctl"></param>
  69. public void AppendText(string str, Color color, Control ctl)
  70. {
  71. SelectionColor = color;
  72. base.AppendText(str);
  73. ctl.Text = "";
  74. //如果颜色是红色则进行提示音
  75. if (color == Color.Red && Entity.SystemInf.CheckAudioEnable)
  76. {
  77. FileName = Application.StartupPath + @"\Resources\Sound\FAIL.wav";
  78. thread.Start();
  79. thread = new Thread(PlaySound);
  80. }
  81. else if (color == Color.Green && Entity.SystemInf.CheckAudioEnable)
  82. {
  83. //颜色是绿色,进行正确提示音
  84. FileName = Application.StartupPath + @"\Resources\Sound\PASS.wav";
  85. thread.Start();
  86. thread = new Thread(PlaySound);
  87. }
  88. else if (color == Color.Blue && Entity.SystemInf.CheckAudioEnable)
  89. {
  90. //颜色是绿色,进行正确提示音
  91. FileName = Application.StartupPath + @"\Resources\Sound\4082.wav";
  92. thread.Start();
  93. thread = new Thread(PlaySound);
  94. }
  95. else if (color == Color.OrangeRed && Entity.SystemInf.CheckAudioEnable)
  96. {
  97. //颜色是绿色,进行正确提示音
  98. FileName = Application.StartupPath + @"\Resources\Sound\失败.wav";
  99. thread.Start();
  100. thread = new Thread(PlaySound);
  101. }
  102. else if (color == Color.Aqua && Entity.SystemInf.CheckAudioEnable)
  103. {
  104. //颜色是绿色,进行正确提示音
  105. FileName = Application.StartupPath + @"\Resources\Sound\打印.wav";
  106. thread.Start();
  107. thread = new Thread(PlaySound);
  108. }
  109. else if (color == Color.Aquamarine && Entity.SystemInf.CheckAudioEnable)
  110. {
  111. //颜色是绿色,进行正确提示音
  112. FileName = Application.StartupPath + @"\Resources\Sound\批过.wav";
  113. thread.Start();
  114. thread = new Thread(PlaySound);
  115. }
  116. else if (color == Color.Brown && Entity.SystemInf.CheckAudioEnable)
  117. {
  118. //颜色是绿色,进行正确提示音
  119. FileName = Application.StartupPath + @"\Resources\Sound\批退.wav";
  120. thread.Start();
  121. thread = new Thread(PlaySound);
  122. }
  123. else if (color == Color.Chartreuse && Entity.SystemInf.CheckAudioEnable)
  124. {
  125. //颜色是绿色,进行正确提示音
  126. FileName = Application.StartupPath + @"\Resources\Sound\强制批过.wav";
  127. thread.Start();
  128. thread = new Thread(PlaySound);
  129. }
  130. else if (color == Color.Crimson && Entity.SystemInf.CheckAudioEnable)
  131. {
  132. //颜色是绿色,进行正确提示音
  133. FileName = Application.StartupPath + @"\Resources\Sound\强制批退.wav";
  134. thread.Start();
  135. thread = new Thread(PlaySound);
  136. }
  137. else if (color == Color.ForestGreen && Entity.SystemInf.CheckAudioEnable)
  138. {
  139. //颜色是绿色,进行正确提示音
  140. FileName = Application.StartupPath + @"\Resources\Sound\已封箱.wav";
  141. thread.Start();
  142. thread = new Thread(PlaySound);
  143. }
  144. else if (color == Color.LawnGreen && Entity.SystemInf.CheckAudioEnable)
  145. {
  146. //颜色是绿色,进行正确提示音
  147. FileName = Application.StartupPath + @"\Resources\Sound\转码成功.wav";
  148. thread.Start();
  149. thread = new Thread(PlaySound);
  150. }
  151. else if (color == Color.CornflowerBlue && Entity.SystemInf.CheckAudioEnable)
  152. {
  153. //颜色是绿色,进行正确提示音
  154. FileName = Application.StartupPath + @"\Resources\Sound\老化开始.wav";
  155. thread.Start();
  156. thread = new Thread(PlaySound);
  157. }
  158. else if (color == Color.LightGreen && Entity.SystemInf.CheckAudioEnable)
  159. {
  160. //颜色是绿色,进行正确提示音
  161. FileName = Application.StartupPath + @"\Resources\Sound\老化结束.wav";
  162. thread.Start();
  163. thread = new Thread(PlaySound);
  164. }
  165. LogManager.DoLog(FindForm().Tag + str);
  166. }
  167. /// <summary>
  168. /// 提示错误信息清楚指定控件的值
  169. /// </summary>
  170. /// <param name="str"></param>
  171. /// <param name="color"></param>
  172. /// <param name="ctl"></param>
  173. public void AppendText(string str, Color color, Control ctl, Control ct2)
  174. {
  175. SelectionColor = color;
  176. base.AppendText(str);
  177. ctl.Text = "";
  178. ct2.Text = "";
  179. //如果颜色是红色则进行提示音
  180. if (color == Color.Red && Entity.SystemInf.CheckAudioEnable)
  181. {
  182. FileName = Application.StartupPath + @"\Resources\Sound\FAIL.wav";
  183. thread.Start();
  184. thread = new Thread(PlaySound);
  185. }
  186. else if (color == Color.Green && Entity.SystemInf.CheckAudioEnable)
  187. {
  188. //颜色是绿色,进行正确提示音
  189. FileName = Application.StartupPath + @"\Resources\Sound\PASS.wav";
  190. thread.Start();
  191. thread = new Thread(PlaySound);
  192. }
  193. else if (color == Color.Blue && Entity.SystemInf.CheckAudioEnable)
  194. {
  195. //颜色是绿色,进行正确提示音
  196. FileName = Application.StartupPath + @"\Resources\Sound\4082.wav";
  197. thread.Start();
  198. thread = new Thread(PlaySound);
  199. }
  200. else if (color == Color.OrangeRed && Entity.SystemInf.CheckAudioEnable)
  201. {
  202. //颜色是绿色,进行正确提示音
  203. FileName = Application.StartupPath + @"\Resources\Sound\失败.wav";
  204. thread.Start();
  205. thread = new Thread(PlaySound);
  206. }
  207. else if (color == Color.Aqua && Entity.SystemInf.CheckAudioEnable)
  208. {
  209. //颜色是绿色,进行正确提示音
  210. FileName = Application.StartupPath + @"\Resources\Sound\打印.wav";
  211. thread.Start();
  212. thread = new Thread(PlaySound);
  213. }
  214. else if (color == Color.Aquamarine && Entity.SystemInf.CheckAudioEnable)
  215. {
  216. //颜色是绿色,进行正确提示音
  217. FileName = Application.StartupPath + @"\Resources\Sound\批过.wav";
  218. thread.Start();
  219. thread = new Thread(PlaySound);
  220. }
  221. else if (color == Color.Brown && Entity.SystemInf.CheckAudioEnable)
  222. {
  223. //颜色是绿色,进行正确提示音
  224. FileName = Application.StartupPath + @"\Resources\Sound\批退.wav";
  225. thread.Start();
  226. thread = new Thread(PlaySound);
  227. }
  228. else if (color == Color.Chartreuse && Entity.SystemInf.CheckAudioEnable)
  229. {
  230. //颜色是绿色,进行正确提示音
  231. FileName = Application.StartupPath + @"\Resources\Sound\强制批过.wav";
  232. thread.Start();
  233. thread = new Thread(PlaySound);
  234. }
  235. else if (color == Color.Crimson && Entity.SystemInf.CheckAudioEnable)
  236. {
  237. //颜色是绿色,进行正确提示音
  238. FileName = Application.StartupPath + @"\Resources\Sound\强制批退.wav";
  239. thread.Start();
  240. thread = new Thread(PlaySound);
  241. }
  242. else if (color == Color.ForestGreen && Entity.SystemInf.CheckAudioEnable)
  243. {
  244. //颜色是绿色,进行正确提示音
  245. FileName = Application.StartupPath + @"\Resources\Sound\已封箱.wav";
  246. thread.Start();
  247. thread = new Thread(PlaySound);
  248. }
  249. else if (color == Color.LawnGreen && Entity.SystemInf.CheckAudioEnable)
  250. {
  251. //颜色是绿色,进行正确提示音
  252. FileName = Application.StartupPath + @"\Resources\Sound\转码成功.wav";
  253. thread.Start();
  254. thread = new Thread(PlaySound);
  255. }
  256. else if (color == Color.CornflowerBlue && Entity.SystemInf.CheckAudioEnable)
  257. {
  258. //颜色是绿色,进行正确提示音
  259. FileName = Application.StartupPath + @"\Resources\Sound\老化开始.wav";
  260. thread.Start();
  261. thread = new Thread(PlaySound);
  262. }
  263. else if (color == Color.LightGreen && Entity.SystemInf.CheckAudioEnable)
  264. {
  265. //颜色是绿色,进行正确提示音
  266. FileName = Application.StartupPath + @"\Resources\Sound\老化结束.wav";
  267. thread.Start();
  268. thread = new Thread(PlaySound);
  269. }
  270. LogManager.DoLog(FindForm().Tag + str);
  271. }
  272. /// <summary>
  273. /// 提示错误信息清楚指定控件的值
  274. /// </summary>
  275. /// <param name="str"></param>
  276. /// <param name="color"></param>
  277. /// <param name="ctl"></param>
  278. public void AppendText(string str, Color color, Control ctl, Control ct2, Control ct3)
  279. {
  280. SelectionColor = color;
  281. base.AppendText(str);
  282. ctl.Text = "";
  283. ct2.Text = "";
  284. ct3.Text = "";
  285. //如果颜色是红色则进行提示音
  286. if (color == Color.Red && Entity.SystemInf.CheckAudioEnable)
  287. {
  288. FileName = Application.StartupPath + @"\Resources\Sound\FAIL.wav";
  289. thread.Start();
  290. thread = new Thread(PlaySound);
  291. }
  292. else if (color == Color.Green && Entity.SystemInf.CheckAudioEnable)
  293. {
  294. //颜色是绿色,进行正确提示音
  295. FileName = Application.StartupPath + @"\Resources\Sound\PASS.wav";
  296. thread.Start();
  297. thread = new Thread(PlaySound);
  298. }
  299. else if (color == Color.Blue && Entity.SystemInf.CheckAudioEnable)
  300. {
  301. //颜色是绿色,进行正确提示音
  302. FileName = Application.StartupPath + @"\Resources\Sound\4082.wav";
  303. thread.Start();
  304. thread = new Thread(PlaySound);
  305. }
  306. else if (color == Color.OrangeRed && Entity.SystemInf.CheckAudioEnable)
  307. {
  308. //颜色是绿色,进行正确提示音
  309. FileName = Application.StartupPath + @"\Resources\Sound\失败.wav";
  310. thread.Start();
  311. thread = new Thread(PlaySound);
  312. }
  313. else if (color == Color.Aqua && Entity.SystemInf.CheckAudioEnable)
  314. {
  315. //颜色是绿色,进行正确提示音
  316. FileName = Application.StartupPath + @"\Resources\Sound\打印.wav";
  317. thread.Start();
  318. thread = new Thread(PlaySound);
  319. }
  320. else if (color == Color.Aquamarine && Entity.SystemInf.CheckAudioEnable)
  321. {
  322. //颜色是绿色,进行正确提示音
  323. FileName = Application.StartupPath + @"\Resources\Sound\批过.wav";
  324. thread.Start();
  325. thread = new Thread(PlaySound);
  326. }
  327. else if (color == Color.Brown && Entity.SystemInf.CheckAudioEnable)
  328. {
  329. //颜色是绿色,进行正确提示音
  330. FileName = Application.StartupPath + @"\Resources\Sound\批退.wav";
  331. thread.Start();
  332. thread = new Thread(PlaySound);
  333. }
  334. else if (color == Color.Chartreuse && Entity.SystemInf.CheckAudioEnable)
  335. {
  336. //颜色是绿色,进行正确提示音
  337. FileName = Application.StartupPath + @"\Resources\Sound\强制批过.wav";
  338. thread.Start();
  339. thread = new Thread(PlaySound);
  340. }
  341. else if (color == Color.Crimson && Entity.SystemInf.CheckAudioEnable)
  342. {
  343. //颜色是绿色,进行正确提示音
  344. FileName = Application.StartupPath + @"\Resources\Sound\强制批退.wav";
  345. thread.Start();
  346. thread = new Thread(PlaySound);
  347. }
  348. else if (color == Color.ForestGreen && Entity.SystemInf.CheckAudioEnable)
  349. {
  350. //颜色是绿色,进行正确提示音
  351. FileName = Application.StartupPath + @"\Resources\Sound\已封箱.wav";
  352. thread.Start();
  353. thread = new Thread(PlaySound);
  354. }
  355. else if (color == Color.LawnGreen && Entity.SystemInf.CheckAudioEnable)
  356. {
  357. //颜色是绿色,进行正确提示音
  358. FileName = Application.StartupPath + @"\Resources\Sound\转码成功.wav";
  359. thread.Start();
  360. thread = new Thread(PlaySound);
  361. }
  362. else if (color == Color.CornflowerBlue && Entity.SystemInf.CheckAudioEnable)
  363. {
  364. //颜色是绿色,进行正确提示音
  365. FileName = Application.StartupPath + @"\Resources\Sound\老化开始.wav";
  366. thread.Start();
  367. thread = new Thread(PlaySound);
  368. }
  369. else if (color == Color.LightGreen && Entity.SystemInf.CheckAudioEnable)
  370. {
  371. //颜色是绿色,进行正确提示音
  372. FileName = Application.StartupPath + @"\Resources\Sound\老化结束.wav";
  373. thread.Start();
  374. thread = new Thread(PlaySound);
  375. }
  376. LogManager.DoLog(FindForm().Tag + str);
  377. }
  378. private void PlaySound()
  379. {
  380. //要加载COM组件:Microsoft speech object Library
  381. if (!System.IO.File.Exists(FileName))
  382. {
  383. return;
  384. }
  385. try
  386. {
  387. SoundPlayer player = new SoundPlayer();
  388. player.SoundLocation = FileName;
  389. player.Load();
  390. player.Play();
  391. }
  392. catch (Exception e)
  393. {
  394. MessageBox.Show(e.Message);
  395. Entity.SystemInf.CheckAudioEnable = false;
  396. }
  397. }
  398. }
  399. }