RichTextAutoBottom.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. else if (color == Color.Aqua && Entity.SystemInf.CheckAudioEnable)
  62. {
  63. //颜色是绿色,进行正确提示音
  64. FileName = Application.StartupPath + @"\Resources\Sound\打印.wav";
  65. thread.Start();
  66. thread = new Thread(PlaySound);
  67. }
  68. else if (color == Color.Aquamarine && Entity.SystemInf.CheckAudioEnable)
  69. {
  70. //颜色是绿色,进行正确提示音
  71. FileName = Application.StartupPath + @"\Resources\Sound\批过.wav";
  72. thread.Start();
  73. thread = new Thread(PlaySound);
  74. }
  75. else if (color == Color.Brown && Entity.SystemInf.CheckAudioEnable)
  76. {
  77. //颜色是绿色,进行正确提示音
  78. FileName = Application.StartupPath + @"\Resources\Sound\批退.wav";
  79. thread.Start();
  80. thread = new Thread(PlaySound);
  81. }
  82. else if (color == Color.Chartreuse && Entity.SystemInf.CheckAudioEnable)
  83. {
  84. //颜色是绿色,进行正确提示音
  85. FileName = Application.StartupPath + @"\Resources\Sound\强制批过.wav";
  86. thread.Start();
  87. thread = new Thread(PlaySound);
  88. }
  89. else if (color == Color.Crimson && Entity.SystemInf.CheckAudioEnable)
  90. {
  91. //颜色是绿色,进行正确提示音
  92. FileName = Application.StartupPath + @"\Resources\Sound\强制批退.wav";
  93. thread.Start();
  94. thread = new Thread(PlaySound);
  95. }
  96. else if (color == Color.ForestGreen && Entity.SystemInf.CheckAudioEnable)
  97. {
  98. //颜色是绿色,进行正确提示音
  99. FileName = Application.StartupPath + @"\Resources\Sound\已封箱.wav";
  100. thread.Start();
  101. thread = new Thread(PlaySound);
  102. }
  103. else if (color == Color.LawnGreen && Entity.SystemInf.CheckAudioEnable)
  104. {
  105. //颜色是绿色,进行正确提示音
  106. FileName = Application.StartupPath + @"\Resources\Sound\转码成功.wav";
  107. thread.Start();
  108. thread = new Thread(PlaySound);
  109. }
  110. else if (color == Color.CornflowerBlue && Entity.SystemInf.CheckAudioEnable)
  111. {
  112. //颜色是绿色,进行正确提示音
  113. FileName = Application.StartupPath + @"\Resources\Sound\老化开始.wav";
  114. thread.Start();
  115. thread = new Thread(PlaySound);
  116. }
  117. else if (color == Color.LightGreen && Entity.SystemInf.CheckAudioEnable)
  118. {
  119. //颜色是绿色,进行正确提示音
  120. FileName = Application.StartupPath + @"\Resources\Sound\老化结束.wav";
  121. thread.Start();
  122. thread = new Thread(PlaySound);
  123. }
  124. LogManager.DoLog(FindForm().Tag + str);
  125. }
  126. /// <summary>
  127. /// 提示错误信息清楚指定控件的值
  128. /// </summary>
  129. /// <param name="str"></param>
  130. /// <param name="color"></param>
  131. /// <param name="ctl"></param>
  132. public void AppendText(string str, Color color, Control ctl)
  133. {
  134. SelectionColor = color;
  135. base.AppendText(str);
  136. ctl.Text = "";
  137. //如果颜色是红色则进行提示音
  138. if (color == Color.Red && Entity.SystemInf.CheckAudioEnable)
  139. {
  140. FileName = Application.StartupPath + @"\Resources\Sound\FAIL.wav";
  141. thread.Start();
  142. thread = new Thread(PlaySound);
  143. }
  144. else if (color == Color.Green && Entity.SystemInf.CheckAudioEnable)
  145. {
  146. //颜色是绿色,进行正确提示音
  147. FileName = Application.StartupPath + @"\Resources\Sound\PASS.wav";
  148. thread.Start();
  149. thread = new Thread(PlaySound);
  150. }
  151. else if (color == Color.Blue && Entity.SystemInf.CheckAudioEnable)
  152. {
  153. //颜色是绿色,进行正确提示音
  154. FileName = Application.StartupPath + @"\Resources\Sound\4082.wav";
  155. thread.Start();
  156. thread = new Thread(PlaySound);
  157. }
  158. else if (color == Color.OrangeRed && Entity.SystemInf.CheckAudioEnable)
  159. {
  160. //颜色是绿色,进行正确提示音
  161. FileName = Application.StartupPath + @"\Resources\Sound\失败.wav";
  162. thread.Start();
  163. thread = new Thread(PlaySound);
  164. }
  165. else if (color == Color.Aqua && Entity.SystemInf.CheckAudioEnable)
  166. {
  167. //颜色是绿色,进行正确提示音
  168. FileName = Application.StartupPath + @"\Resources\Sound\打印.wav";
  169. thread.Start();
  170. thread = new Thread(PlaySound);
  171. }
  172. else if (color == Color.Aquamarine && Entity.SystemInf.CheckAudioEnable)
  173. {
  174. //颜色是绿色,进行正确提示音
  175. FileName = Application.StartupPath + @"\Resources\Sound\批过.wav";
  176. thread.Start();
  177. thread = new Thread(PlaySound);
  178. }
  179. else if (color == Color.Brown && Entity.SystemInf.CheckAudioEnable)
  180. {
  181. //颜色是绿色,进行正确提示音
  182. FileName = Application.StartupPath + @"\Resources\Sound\批退.wav";
  183. thread.Start();
  184. thread = new Thread(PlaySound);
  185. }
  186. else if (color == Color.Chartreuse && Entity.SystemInf.CheckAudioEnable)
  187. {
  188. //颜色是绿色,进行正确提示音
  189. FileName = Application.StartupPath + @"\Resources\Sound\强制批过.wav";
  190. thread.Start();
  191. thread = new Thread(PlaySound);
  192. }
  193. else if (color == Color.Crimson && Entity.SystemInf.CheckAudioEnable)
  194. {
  195. //颜色是绿色,进行正确提示音
  196. FileName = Application.StartupPath + @"\Resources\Sound\强制批退.wav";
  197. thread.Start();
  198. thread = new Thread(PlaySound);
  199. }
  200. else if (color == Color.ForestGreen && 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.LawnGreen && 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.CornflowerBlue && 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.LightGreen && Entity.SystemInf.CheckAudioEnable)
  222. {
  223. //颜色是绿色,进行正确提示音
  224. FileName = Application.StartupPath + @"\Resources\Sound\老化结束.wav";
  225. thread.Start();
  226. thread = new Thread(PlaySound);
  227. }
  228. LogManager.DoLog(FindForm().Tag + str);
  229. }
  230. /// <summary>
  231. /// 提示错误信息清楚指定控件的值
  232. /// </summary>
  233. /// <param name="str"></param>
  234. /// <param name="color"></param>
  235. /// <param name="ctl"></param>
  236. public void AppendText(string str, Color color, Control ctl, Control ct2)
  237. {
  238. SelectionColor = color;
  239. base.AppendText(str);
  240. ctl.Text = "";
  241. ct2.Text = "";
  242. //如果颜色是红色则进行提示音
  243. if (color == Color.Red && Entity.SystemInf.CheckAudioEnable)
  244. {
  245. FileName = Application.StartupPath + @"\Resources\Sound\FAIL.wav";
  246. thread.Start();
  247. thread = new Thread(PlaySound);
  248. }
  249. else if (color == Color.Green && Entity.SystemInf.CheckAudioEnable)
  250. {
  251. //颜色是绿色,进行正确提示音
  252. FileName = Application.StartupPath + @"\Resources\Sound\PASS.wav";
  253. thread.Start();
  254. thread = new Thread(PlaySound);
  255. }
  256. else if (color == Color.Blue && Entity.SystemInf.CheckAudioEnable)
  257. {
  258. //颜色是绿色,进行正确提示音
  259. FileName = Application.StartupPath + @"\Resources\Sound\4082.wav";
  260. thread.Start();
  261. thread = new Thread(PlaySound);
  262. }
  263. else if (color == Color.OrangeRed && Entity.SystemInf.CheckAudioEnable)
  264. {
  265. //颜色是绿色,进行正确提示音
  266. FileName = Application.StartupPath + @"\Resources\Sound\失败.wav";
  267. thread.Start();
  268. thread = new Thread(PlaySound);
  269. }
  270. else if (color == Color.Aqua && Entity.SystemInf.CheckAudioEnable)
  271. {
  272. //颜色是绿色,进行正确提示音
  273. FileName = Application.StartupPath + @"\Resources\Sound\打印.wav";
  274. thread.Start();
  275. thread = new Thread(PlaySound);
  276. }
  277. else if (color == Color.Aquamarine && Entity.SystemInf.CheckAudioEnable)
  278. {
  279. //颜色是绿色,进行正确提示音
  280. FileName = Application.StartupPath + @"\Resources\Sound\批过.wav";
  281. thread.Start();
  282. thread = new Thread(PlaySound);
  283. }
  284. else if (color == Color.Brown && Entity.SystemInf.CheckAudioEnable)
  285. {
  286. //颜色是绿色,进行正确提示音
  287. FileName = Application.StartupPath + @"\Resources\Sound\批退.wav";
  288. thread.Start();
  289. thread = new Thread(PlaySound);
  290. }
  291. else if (color == Color.Chartreuse && Entity.SystemInf.CheckAudioEnable)
  292. {
  293. //颜色是绿色,进行正确提示音
  294. FileName = Application.StartupPath + @"\Resources\Sound\强制批过.wav";
  295. thread.Start();
  296. thread = new Thread(PlaySound);
  297. }
  298. else if (color == Color.Crimson && Entity.SystemInf.CheckAudioEnable)
  299. {
  300. //颜色是绿色,进行正确提示音
  301. FileName = Application.StartupPath + @"\Resources\Sound\强制批退.wav";
  302. thread.Start();
  303. thread = new Thread(PlaySound);
  304. }
  305. else if (color == Color.ForestGreen && Entity.SystemInf.CheckAudioEnable)
  306. {
  307. //颜色是绿色,进行正确提示音
  308. FileName = Application.StartupPath + @"\Resources\Sound\已封箱.wav";
  309. thread.Start();
  310. thread = new Thread(PlaySound);
  311. }
  312. else if (color == Color.LawnGreen && Entity.SystemInf.CheckAudioEnable)
  313. {
  314. //颜色是绿色,进行正确提示音
  315. FileName = Application.StartupPath + @"\Resources\Sound\转码成功.wav";
  316. thread.Start();
  317. thread = new Thread(PlaySound);
  318. }
  319. else if (color == Color.CornflowerBlue && Entity.SystemInf.CheckAudioEnable)
  320. {
  321. //颜色是绿色,进行正确提示音
  322. FileName = Application.StartupPath + @"\Resources\Sound\老化开始.wav";
  323. thread.Start();
  324. thread = new Thread(PlaySound);
  325. }
  326. else if (color == Color.LightGreen && Entity.SystemInf.CheckAudioEnable)
  327. {
  328. //颜色是绿色,进行正确提示音
  329. FileName = Application.StartupPath + @"\Resources\Sound\老化结束.wav";
  330. thread.Start();
  331. thread = new Thread(PlaySound);
  332. }
  333. LogManager.DoLog(FindForm().Tag + str);
  334. }
  335. /// <summary>
  336. /// 提示错误信息清楚指定控件的值
  337. /// </summary>
  338. /// <param name="str"></param>
  339. /// <param name="color"></param>
  340. /// <param name="ctl"></param>
  341. public void AppendText(string str, Color color, Control ctl, Control ct2, Control ct3)
  342. {
  343. SelectionColor = color;
  344. base.AppendText(str);
  345. ctl.Text = "";
  346. ct2.Text = "";
  347. ct3.Text = "";
  348. //如果颜色是红色则进行提示音
  349. if (color == Color.Red && Entity.SystemInf.CheckAudioEnable)
  350. {
  351. FileName = Application.StartupPath + @"\Resources\Sound\FAIL.wav";
  352. thread.Start();
  353. thread = new Thread(PlaySound);
  354. }
  355. else if (color == Color.Green && Entity.SystemInf.CheckAudioEnable)
  356. {
  357. //颜色是绿色,进行正确提示音
  358. FileName = Application.StartupPath + @"\Resources\Sound\PASS.wav";
  359. thread.Start();
  360. thread = new Thread(PlaySound);
  361. }
  362. else if (color == Color.Blue && Entity.SystemInf.CheckAudioEnable)
  363. {
  364. //颜色是绿色,进行正确提示音
  365. FileName = Application.StartupPath + @"\Resources\Sound\4082.wav";
  366. thread.Start();
  367. thread = new Thread(PlaySound);
  368. }
  369. else if (color == Color.OrangeRed && Entity.SystemInf.CheckAudioEnable)
  370. {
  371. //颜色是绿色,进行正确提示音
  372. FileName = Application.StartupPath + @"\Resources\Sound\失败.wav";
  373. thread.Start();
  374. thread = new Thread(PlaySound);
  375. }
  376. else if (color == Color.Aqua && Entity.SystemInf.CheckAudioEnable)
  377. {
  378. //颜色是绿色,进行正确提示音
  379. FileName = Application.StartupPath + @"\Resources\Sound\打印.wav";
  380. thread.Start();
  381. thread = new Thread(PlaySound);
  382. }
  383. else if (color == Color.Aquamarine && Entity.SystemInf.CheckAudioEnable)
  384. {
  385. //颜色是绿色,进行正确提示音
  386. FileName = Application.StartupPath + @"\Resources\Sound\批过.wav";
  387. thread.Start();
  388. thread = new Thread(PlaySound);
  389. }
  390. else if (color == Color.Brown && Entity.SystemInf.CheckAudioEnable)
  391. {
  392. //颜色是绿色,进行正确提示音
  393. FileName = Application.StartupPath + @"\Resources\Sound\批退.wav";
  394. thread.Start();
  395. thread = new Thread(PlaySound);
  396. }
  397. else if (color == Color.Chartreuse && Entity.SystemInf.CheckAudioEnable)
  398. {
  399. //颜色是绿色,进行正确提示音
  400. FileName = Application.StartupPath + @"\Resources\Sound\强制批过.wav";
  401. thread.Start();
  402. thread = new Thread(PlaySound);
  403. }
  404. else if (color == Color.Crimson && Entity.SystemInf.CheckAudioEnable)
  405. {
  406. //颜色是绿色,进行正确提示音
  407. FileName = Application.StartupPath + @"\Resources\Sound\强制批退.wav";
  408. thread.Start();
  409. thread = new Thread(PlaySound);
  410. }
  411. else if (color == Color.ForestGreen && Entity.SystemInf.CheckAudioEnable)
  412. {
  413. //颜色是绿色,进行正确提示音
  414. FileName = Application.StartupPath + @"\Resources\Sound\已封箱.wav";
  415. thread.Start();
  416. thread = new Thread(PlaySound);
  417. }
  418. else if (color == Color.LawnGreen && Entity.SystemInf.CheckAudioEnable)
  419. {
  420. //颜色是绿色,进行正确提示音
  421. FileName = Application.StartupPath + @"\Resources\Sound\转码成功.wav";
  422. thread.Start();
  423. thread = new Thread(PlaySound);
  424. }
  425. else if (color == Color.CornflowerBlue && Entity.SystemInf.CheckAudioEnable)
  426. {
  427. //颜色是绿色,进行正确提示音
  428. FileName = Application.StartupPath + @"\Resources\Sound\老化开始.wav";
  429. thread.Start();
  430. thread = new Thread(PlaySound);
  431. }
  432. else if (color == Color.LightGreen && Entity.SystemInf.CheckAudioEnable)
  433. {
  434. //颜色是绿色,进行正确提示音
  435. FileName = Application.StartupPath + @"\Resources\Sound\老化结束.wav";
  436. thread.Start();
  437. thread = new Thread(PlaySound);
  438. }
  439. LogManager.DoLog(FindForm().Tag + str);
  440. }
  441. private void PlaySound()
  442. {
  443. //要加载COM组件:Microsoft speech object Library
  444. if (!System.IO.File.Exists(FileName))
  445. {
  446. return;
  447. }
  448. try
  449. {
  450. SoundPlayer player = new SoundPlayer();
  451. player.SoundLocation = FileName;
  452. player.Load();
  453. player.Play();
  454. }
  455. catch (Exception e)
  456. {
  457. MessageBox.Show(e.Message);
  458. Entity.SystemInf.CheckAudioEnable = false;
  459. }
  460. }
  461. }
  462. }