Title.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 IntelligentControlForsx.Code;
  11. using log4net;
  12. namespace IntelligentControlForsx.MyControls
  13. {
  14. public partial class Title : UserControl
  15. {
  16. private ILog logger = LogManager.GetLogger("AppInfoLog");
  17. /// <summary>
  18. /// 鼠标悬停取得图片路径
  19. /// </summary>
  20. Dictionary<string, string> mouseEnterDic = new Dictionary<string, string>();
  21. /// <summary>
  22. /// 鼠标离开取得图片路径
  23. /// </summary>
  24. Dictionary<string, string> mouseLeaveDic = new Dictionary<string, string>();
  25. /// <summary>
  26. /// 鼠标离开取得图片路径
  27. /// </summary>
  28. //Dictionary<string, PictureBox> pictureDic = new Dictionary<string, PictureBox>();
  29. /// <summary>
  30. /// 鼠标点击跳转页面地址
  31. /// </summary>
  32. Dictionary<string, string> mouseClickDic = new Dictionary<string, string>();
  33. string path = UserTools.Path;
  34. public Title()
  35. {
  36. InitializeComponent();
  37. if (!this.DesignMode)
  38. {
  39. string homeStr = path + @"\images\导航1.png";
  40. string matrixStr = path + @"\images\导航2.png";
  41. string paramtersStr = path + @"\images\导航3.png";
  42. string controlStr = path + @"\images\ZDQT1.png";
  43. string mainParamStr = path + @"\images\导航5.png";
  44. string statisticsStr = path + @"\images\导航6.png";
  45. string faultStr = path + @"\images\导航7.png";
  46. string electricalStr = path + @"\images\导航8.png";
  47. string windturbineStr = path + @"\images\fj1.png";
  48. string syzStr = path + @"\images\导航8.png";
  49. string agcStr = path + @"\images\agc1.png";
  50. string homeStr2 = path + @"\images\导航11.png";
  51. string matrixStr2 = path + @"\images\导航12.png";
  52. string paramtersStr2 = path + @"\images\导航13.png";
  53. string controlStr2 = path + @"\images\ZDQT2.png";
  54. string mainParamStr2 = path + @"\images\导航15.png";
  55. string statisticsStr2 = path + @"\images\导航16.png";
  56. string faultStr2 = path + @"\images\导航17.png";
  57. string electricalStr2 = path + @"\images\导航18.png";
  58. string windturbineStr2 = path + @"\images\fj11.png";
  59. string syzStr2 = path + @"\images\导航18.png";
  60. string agcStr2 = path + @"\images\agc11.png";
  61. mouseLeaveDic.Add(this.pictureBoxHome.Name, homeStr);
  62. mouseLeaveDic.Add(this.pictureBoxMatrix.Name, matrixStr);
  63. mouseLeaveDic.Add(this.pictureBoxParamters.Name, paramtersStr);
  64. mouseLeaveDic.Add(this.pictureBoxControl.Name, controlStr);
  65. mouseLeaveDic.Add(this.pictureBoxMainParam.Name, mainParamStr);
  66. mouseLeaveDic.Add(this.pictureBoxStatistics.Name, statisticsStr);
  67. mouseLeaveDic.Add(this.pictureBoxElectrical.Name, electricalStr);
  68. mouseLeaveDic.Add(this.pictureBoxWindturbine.Name, windturbineStr);
  69. mouseLeaveDic.Add(this.pictureBoxSYZ.Name, syzStr);
  70. mouseLeaveDic.Add(this.pictureBoxAGC.Name, agcStr);
  71. mouseEnterDic.Add(this.pictureBoxHome.Name, homeStr2);
  72. mouseEnterDic.Add(this.pictureBoxMatrix.Name, matrixStr2);
  73. mouseEnterDic.Add(this.pictureBoxParamters.Name, paramtersStr2);
  74. mouseEnterDic.Add(this.pictureBoxControl.Name, controlStr2);
  75. mouseEnterDic.Add(this.pictureBoxMainParam.Name, mainParamStr2);
  76. mouseEnterDic.Add(this.pictureBoxStatistics.Name, statisticsStr2);
  77. mouseEnterDic.Add(this.pictureBoxElectrical.Name, electricalStr2);
  78. mouseEnterDic.Add(this.pictureBoxWindturbine.Name, windturbineStr2);
  79. mouseEnterDic.Add(this.pictureBoxSYZ.Name, syzStr2);
  80. mouseEnterDic.Add(this.pictureBoxAGC.Name, agcStr2);
  81. //pictureDic.Add(0, this.pictureBoxHome);
  82. //pictureDic.Add(1, this.pictureBoxMatrix);
  83. //pictureDic.Add(2, this.pictureBoxParamters);
  84. //pictureDic.Add(3, this.pictureBoxControl);
  85. //pictureDic.Add(4, this.pictureBoxMainParam);
  86. //pictureDic.Add(5, this.pictureBoxStatistics);
  87. //pictureDic.Add(6, this.pictureBoxFault);
  88. //pictureDic.Add(7, this.pictureBoxElectrical);
  89. this.pictureBoxHome.Cursor = System.Windows.Forms.Cursors.Hand;
  90. this.pictureBoxMatrix.Cursor = System.Windows.Forms.Cursors.Hand;
  91. this.pictureBoxParamters.Cursor = System.Windows.Forms.Cursors.Hand;
  92. this.pictureBoxControl.Cursor = System.Windows.Forms.Cursors.Hand;
  93. this.pictureBoxMainParam.Cursor = System.Windows.Forms.Cursors.Hand;
  94. this.pictureBoxStatistics.Cursor = System.Windows.Forms.Cursors.Hand;
  95. this.pictureBoxElectrical.Cursor = System.Windows.Forms.Cursors.Hand;
  96. this.pictureBoxWindturbine.Cursor = System.Windows.Forms.Cursors.Hand;
  97. this.pictureBoxSYZ.Cursor = System.Windows.Forms.Cursors.Hand;
  98. this.pictureBoxAGC.Cursor = System.Windows.Forms.Cursors.Hand;
  99. defaultPicture = this.pictureBoxHome;
  100. this.defaultPicture.Cursor = System.Windows.Forms.Cursors.Default;
  101. }
  102. }
  103. PictureBox defaultPicture;
  104. [Browsable(true), Category("Appearance")]
  105. public PictureBox DefaultPicture
  106. {
  107. get
  108. {
  109. return defaultPicture;
  110. }
  111. set
  112. {
  113. //if (pictureDic.ContainsKey(value))
  114. //{
  115. if (!this.DesignMode && defaultPicture != value)
  116. {
  117. value.Image = Image.FromFile(mouseEnterDic[value.Name]);
  118. value.Cursor = System.Windows.Forms.Cursors.Default;
  119. defaultPicture.Image = Image.FromFile(mouseLeaveDic[defaultPicture.Name]);
  120. defaultPicture.Cursor = System.Windows.Forms.Cursors.Hand;
  121. }
  122. defaultPicture = value;
  123. //}
  124. }
  125. }
  126. private void pictureBox_MouseEnter(object sender, EventArgs e)
  127. {
  128. if (!this.DesignMode)
  129. {
  130. PictureBox box = (PictureBox)sender;
  131. // MessageBox.Show(defaultPicture.Name + ":" + box.Name);
  132. if (defaultPicture.Name != box.Name)
  133. {
  134. box.Image = Image.FromFile(mouseEnterDic[box.Name]);
  135. }
  136. }
  137. }
  138. private void pictureBox_MouseLeave(object sender, EventArgs e)
  139. {
  140. if (!this.DesignMode)
  141. {
  142. PictureBox box = (PictureBox)sender;
  143. //MessageBox.Show(defaultPicture.Name + ":" + box.Name);
  144. if (defaultPicture.Name != box.Name)
  145. {
  146. box.Image = Image.FromFile(mouseLeaveDic[box.Name]);
  147. }
  148. }
  149. }
  150. public event EventHandler MyClick;
  151. private void pictureBox_Click(object sender, EventArgs e)
  152. {
  153. if (!this.DesignMode)
  154. {
  155. PictureBox box = (PictureBox)sender;
  156. if ("pictureBoxHome".Equals(box.Name) || defaultPicture.Name != box.Name)
  157. {
  158. if (MyClick == null)
  159. {
  160. MessageBox.Show(box.Name);
  161. }
  162. else
  163. {
  164. // MessageBox.Show(box.Name);
  165. MyClick(box.Name, e);
  166. DefaultPicture = box;
  167. }
  168. }
  169. else if (box.Name == "pictureBoxMatrix")
  170. {
  171. if (MyClick == null)
  172. {
  173. MessageBox.Show(box.Name);
  174. }
  175. else
  176. {
  177. // MessageBox.Show(box.Name);
  178. MyClick(box.Name, e);
  179. DefaultPicture = box;
  180. }
  181. }
  182. }
  183. }
  184. private void pictureBoxElectrical_Click(object sender, EventArgs e)
  185. {
  186. this.pictureBoxElectrical.Visible = false;
  187. this.pictureBoxMatrix.Visible = false;
  188. this.pictureBoxParamters.Visible = false;
  189. this.pictureBoxControl.Visible = false;
  190. this.pictureBoxMainParam.Visible = false;
  191. this.pictureBoxStatistics.Visible = false;
  192. this.pictureBoxSYZ.Visible = true;
  193. this.pictureBoxAGC.Visible = true;
  194. this.pictureBoxWindturbine.Visible = true;
  195. }
  196. private void pictureBoxWindturbine_Click(object sender, EventArgs e)
  197. {
  198. this.pictureBoxSYZ.Visible = false;
  199. this.pictureBoxAGC.Visible = false;
  200. this.pictureBoxWindturbine.Visible = false;
  201. this.pictureBoxElectrical.Visible = true;
  202. this.pictureBoxMatrix.Visible = true;
  203. this.pictureBoxParamters.Visible = true;
  204. this.pictureBoxControl.Visible = true;
  205. this.pictureBoxMainParam.Visible = true;
  206. this.pictureBoxStatistics.Visible = true;
  207. }
  208. public void StyleImgChange(string functionName)
  209. {
  210. if (functionName == "pictureBoxSYZ")
  211. {
  212. this.pictureBoxElectrical.Visible = false;
  213. this.pictureBoxMatrix.Visible = false;
  214. this.pictureBoxParamters.Visible = false;
  215. this.pictureBoxControl.Visible = false;
  216. this.pictureBoxMainParam.Visible = false;
  217. this.pictureBoxStatistics.Visible = false;
  218. this.pictureBoxSYZ.Visible = true;
  219. this.pictureBoxAGC.Visible = true;
  220. this.pictureBoxWindturbine.Visible = true;
  221. }
  222. try
  223. {
  224. PictureBox picBox = (PictureBox)this.Controls.Find(functionName, true).FirstOrDefault();
  225. if (picBox != null)
  226. DefaultPicture = picBox;
  227. }
  228. catch (Exception ex)
  229. {
  230. logger.Info("标题切换失败" + ex.Message);
  231. }
  232. }
  233. // 鼠标进入移出 效果
  234. private void title_main_MouseEnter(object sender, EventArgs e)
  235. {
  236. }
  237. }
  238. }