LibLable.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace YG.Device
  8. {
  9. public class LableLib
  10. {
  11. private static LableLib lableHandle = new LableLib();
  12. public static LableLib Instance { get { return lableHandle; } }
  13. /// <summary>
  14. ///
  15. /// </summary>
  16. /// <param name="lb"></param>
  17. /// <param name="sleeptime">保持绿灯多少毫秒,-1是长亮</param>
  18. public void LableColorChange(System.Windows.Forms.Label lb, int sleeptime)
  19. {
  20. lb.BeginInvoke(new Action(() =>
  21. {
  22. lb.AutoSize = false;
  23. lb.Text = "";
  24. lb.Size = new Size(23, 23);
  25. lb.BackColor = Color.Green;
  26. Task.Factory.StartNew(() =>
  27. {
  28. if (sleeptime > 0)
  29. {
  30. System.Threading.Thread.Sleep(sleeptime);
  31. lb.BackColor = Color.Red;
  32. }
  33. });
  34. }));
  35. }
  36. }
  37. }