Bottom.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using EntityDataSet;
  11. using IntelligentControlForsx.Service;
  12. using log4net.Util;
  13. namespace IntelligentControlForsx.MyControls
  14. {
  15. public partial class Bottom : UserControl
  16. {
  17. private List<Label> labelList=new List<Label>();
  18. public Bottom()
  19. {
  20. InitializeComponent();
  21. }
  22. Label defalutLable;
  23. [Browsable(true), Category("Appearance")]
  24. public Label DefaultLable
  25. {
  26. get
  27. {
  28. return defalutLable;
  29. }
  30. set
  31. {
  32. if (!this.DesignMode)
  33. {
  34. if (defalutLable.Name != null && defalutLable.Name.Trim() != "")
  35. {
  36. value.BackColor = Color.FromArgb(0, 148, 220);
  37. value.Height = 46;
  38. value.Cursor = Cursors.Default;
  39. if (defalutLable.Name != value.Name)
  40. {
  41. defalutLable.BackColor = Color.FromArgb(0, 78, 140);
  42. defalutLable.Height = 37;
  43. defalutLable.Cursor = System.Windows.Forms.Cursors.Hand;
  44. }
  45. }
  46. }
  47. defalutLable = value;
  48. }
  49. }
  50. private void Bottom_Load(object sender, EventArgs e)
  51. {
  52. IList<windpowerstation> lstStation = new List<windpowerstation>();
  53. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  54. {
  55. lstStation = ctx.windpowerstation.Where(s => s.ID.Contains("_FDC")).ToList().OrderByDescending(k => k.NAME).ToList();
  56. }
  57. Panel p = new Panel();
  58. p.Width = lstStation.Count * 100;
  59. p.Height = 37;
  60. int locationX = (1920 - lstStation.Count * 100) / 2;
  61. int locationY = 7;
  62. p.Location = new System.Drawing.Point(locationX, locationY);
  63. this.Controls.Clear();
  64. foreach (var st in lstStation)
  65. {
  66. Label lb = new Label();
  67. lb.Width = 100;
  68. lb.Margin = new Padding(1, 1, 1, 1);
  69. lb.BorderStyle = BorderStyle.FixedSingle;
  70. lb.Name = "lbl" + st.ID;
  71. lb.Tag = st.ID;
  72. lb.Text = st.NAME;
  73. lb.Click += lbl_Click;
  74. lb.MouseEnter += lbl_MouseEnter;
  75. lb.MouseLeave += lbl_MouseLeave;
  76. lb.BackColor = Color.FromArgb(0, 78, 140);
  77. lb.ForeColor = Color.White;
  78. lb.TextAlign = ContentAlignment.MiddleCenter;
  79. lb.Font = new Font("微软雅黑", (float)9, FontStyle.Bold);
  80. lb.Dock = DockStyle.Left;
  81. p.Controls.Add(lb);
  82. labelList.Add(lb);
  83. }
  84. this.Controls.Add(p);
  85. defalutLable = new Label();
  86. }
  87. private void lbl_MouseEnter(object sender, System.EventArgs e)
  88. {
  89. if (!this.DesignMode)
  90. {
  91. Label lable = (Label)sender;
  92. if (defalutLable.Name != lable.Name)
  93. {
  94. lable.Height = 46;
  95. lable.BackColor = Color.FromArgb(0, 148, 220);
  96. }
  97. }
  98. }
  99. private void lbl_MouseLeave(object sender, System.EventArgs e)
  100. {
  101. if (!this.DesignMode)
  102. {
  103. Label lable = (Label)sender;
  104. if (defalutLable.Name != lable.Name)
  105. {
  106. lable.Height = 37;
  107. lable.BackColor = Color.FromArgb(0, 78, 140);
  108. }
  109. }
  110. }
  111. public event EventHandler MyClick;
  112. private void lbl_Click(object sender, System.EventArgs e)
  113. {
  114. if (!this.DesignMode)
  115. {
  116. Label lable = (Label)sender;
  117. MyClick(lable.Tag, e);
  118. DefaultLable = lable;
  119. }
  120. }
  121. public void StationChange(string stationId)
  122. {
  123. foreach (var item in labelList)
  124. {
  125. if (item is Label)
  126. {
  127. Label lb = (Label)item;
  128. if (lb.Name.Replace("lbl", "") == stationId)
  129. {
  130. DefaultLable = lb;
  131. }
  132. }
  133. }
  134. }
  135. }
  136. }