Bottom2.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 Bottom2 : UserControl
  16. {
  17. private List<Label> labelList=new List<Label>();
  18. public Bottom2()
  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 Bottom2_Load(object sender, EventArgs e)
  51. {
  52. try
  53. {
  54. IList<windpowerstation> lstStation = new List<windpowerstation>();
  55. using (wisdom_cs_entity ctx = new wisdom_cs_entity())
  56. {
  57. lstStation = ctx.windpowerstation.Where(s => s.ID.Contains("_FDC")).ToList().OrderBy(k => k.NAME).ToList();
  58. }
  59. Panel p = new Panel();
  60. p.Width = lstStation.Count * 100;
  61. p.Height = 39;
  62. int locationX = (820 - lstStation.Count * 100) / 2;
  63. int locationY = 7;
  64. p.Location = new System.Drawing.Point(locationX, locationY);
  65. // this.Controls.Clear();
  66. foreach (var st in lstStation)
  67. {
  68. Label lb = new Label();
  69. lb.Width = 100;
  70. lb.Height = 39;
  71. lb.Margin = new Padding(1, 1, 1, 1);
  72. lb.BorderStyle = BorderStyle.FixedSingle;
  73. lb.Name = "lbl" + st.ID;
  74. lb.Tag = st.ID;
  75. lb.Text = st.NAME.Replace("电站", "");
  76. lb.Click += lbl_Click;
  77. lb.MouseEnter += lbl_MouseEnter;
  78. lb.MouseLeave += lbl_MouseLeave;
  79. lb.BackColor = Color.FromArgb(0, 78, 140);
  80. lb.ForeColor = Color.White;
  81. lb.TextAlign = ContentAlignment.MiddleCenter;
  82. lb.Font = new Font("微软雅黑", (float)9, FontStyle.Bold);
  83. lb.Dock = DockStyle.Right;
  84. p.Controls.Add(lb);
  85. labelList.Add(lb);
  86. }
  87. this.Controls.Add(p);
  88. defalutLable = new Label();
  89. }
  90. catch
  91. { }
  92. }
  93. private void lbl_MouseEnter(object sender, System.EventArgs e)
  94. {
  95. if (!this.DesignMode)
  96. {
  97. Label lable = (Label)sender;
  98. if (defalutLable.Name != lable.Name)
  99. {
  100. lable.Height = 46;
  101. lable.BackColor = Color.FromArgb(0, 148, 220);
  102. }
  103. }
  104. }
  105. private void lbl_MouseLeave(object sender, System.EventArgs e)
  106. {
  107. if (!this.DesignMode)
  108. {
  109. Label lable = (Label)sender;
  110. if (defalutLable.Name != lable.Name)
  111. {
  112. lable.Height = 37;
  113. lable.BackColor = Color.FromArgb(0, 78, 140);
  114. }
  115. }
  116. }
  117. public event EventHandler MyClick;
  118. private void lbl_Click(object sender, System.EventArgs e)
  119. {
  120. if (!this.DesignMode)
  121. {
  122. Label lable = (Label)sender;
  123. MyClick(lable.Tag, e);
  124. DefaultLable = lable;
  125. }
  126. }
  127. public void StationChange(string stationId)
  128. {
  129. foreach (var item in labelList)
  130. {
  131. if (item is Label)
  132. {
  133. Label lb = (Label)item;
  134. if (lb.Name.Replace("lbl", "") == stationId)
  135. {
  136. DefaultLable = lb;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }