PanelMessage.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. namespace IntelligentControlForsx.Code
  10. {
  11. public class PanelMessage
  12. {
  13. readonly static ConcurrentDictionary<string, TableLayoutPanel> Panels = new ConcurrentDictionary<string, TableLayoutPanel>();
  14. static Thread T;
  15. public static void AddPanel(TableLayoutPanel panels)
  16. {
  17. Panels.TryAdd(panels.Name, panels);
  18. }
  19. public static void DeletePanel(TableLayoutPanel panels)
  20. {
  21. Panels.TryRemove(panels.Name, out panels);
  22. }
  23. public static void SetBackColorTest()
  24. {
  25. T = new Thread(SetPanelText);
  26. T.IsBackground = true;
  27. T.Start();
  28. }
  29. public static void SetPanelText()
  30. {
  31. while (true)
  32. {
  33. Console.WriteLine(Panels.Count);
  34. foreach (TableLayoutPanel l in Panels.Values)
  35. {
  36. if (l.Tag == null)
  37. {
  38. Console.WriteLine("1");
  39. }
  40. if (CommunalTarget.UdpDoubleMemory.ContainsKey(((MyKeyValue<string, int>)l.Tag).Key))
  41. {
  42. Action action1 = () =>
  43. {
  44. GetBackColor(l, (int)CommunalTarget.UdpDoubleMemory[((MyKeyValue<string, int>)l.Tag).Key]);
  45. ((MyKeyValue<string, int>)l.Tag).Value = (int)CommunalTarget.UdpDoubleMemory[((MyKeyValue<string, int>)l.Tag).Key];
  46. };
  47. if (l.IsHandleCreated)
  48. {
  49. try
  50. {
  51. l.Invoke(action1);
  52. }
  53. catch (Exception e)
  54. {
  55. Console.WriteLine(e.Message);
  56. break;
  57. }
  58. }
  59. }
  60. }
  61. Thread.Sleep(1000);
  62. }
  63. }
  64. private static void GetBackColor(TableLayoutPanel panel,int Color)
  65. {
  66. switch (Color)
  67. {
  68. case 0:
  69. {
  70. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(36)))), ((int)(((byte)(161)))), ((int)(((byte)(58)))));
  71. break;
  72. }
  73. case 1:
  74. {
  75. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(36)))), ((int)(((byte)(161)))), ((int)(((byte)(58)))));
  76. break;
  77. }
  78. case 2:
  79. {
  80. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(165)))), ((int)(((byte)(219)))));
  81. break;
  82. }
  83. case 3:
  84. {
  85. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(165)))), ((int)(((byte)(219)))));
  86. break;
  87. }
  88. case 4:
  89. {
  90. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(177)))), ((int)(((byte)(14)))), ((int)(((byte)(126)))));
  91. break;
  92. }
  93. case 5:
  94. {
  95. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(177)))), ((int)(((byte)(14)))), ((int)(((byte)(126)))));
  96. break;
  97. }
  98. case 6:
  99. {
  100. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(203)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));
  101. break;
  102. }
  103. case 7:
  104. {
  105. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(203)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));
  106. break;
  107. }
  108. case 8:
  109. {
  110. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(120)))), ((int)(((byte)(0)))));
  111. break;
  112. }
  113. case 9:
  114. {
  115. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(120)))), ((int)(((byte)(0)))));
  116. break;
  117. }
  118. case 10:
  119. {
  120. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
  121. break;
  122. }
  123. case 11:
  124. {
  125. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
  126. break;
  127. }
  128. case 12:
  129. {
  130. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(146)))), ((int)(((byte)(156)))), ((int)(((byte)(163)))));
  131. break;
  132. }
  133. default:
  134. {
  135. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(64)))));
  136. break;
  137. }
  138. }
  139. }
  140. }
  141. }