Title2.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 Title2 : 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 Title2()
  35. {
  36. InitializeComponent();
  37. if (!this.DesignMode)
  38. {
  39. //string controlStr = path + @"\images\导航4.png";
  40. //string controlStr2 = path + @"\images\导航14.png";
  41. string controlStr = path + @"\images\ZDQT1.png";
  42. string controlStr2 = path + @"\images\ZDQT2.png";
  43. mouseLeaveDic.Add(this.pictureBoxControl.Name, controlStr);
  44. mouseEnterDic.Add(this.pictureBoxControl.Name, controlStr2);
  45. this.pictureBoxControl.Cursor = System.Windows.Forms.Cursors.Hand;
  46. //this.defaultPicture.Cursor = System.Windows.Forms.Cursors.Default;
  47. }
  48. }
  49. PictureBox defaultPicture;
  50. [Browsable(true), Category("Appearance")]
  51. public PictureBox DefaultPicture
  52. {
  53. get
  54. {
  55. return defaultPicture;
  56. }
  57. set
  58. {
  59. if (!this.DesignMode && defaultPicture != value)
  60. {
  61. value.Image = Image.FromFile(mouseEnterDic[value.Name]);
  62. value.Cursor = System.Windows.Forms.Cursors.Default;
  63. }
  64. defaultPicture = value;
  65. }
  66. }
  67. private void pictureBox_MouseEnter(object sender, EventArgs e)
  68. {
  69. if (!this.DesignMode)
  70. {
  71. PictureBox box = (PictureBox)sender;
  72. //if (defaultPicture.Name != box.Name)
  73. //{
  74. // box.Image = Image.FromFile(mouseEnterDic[box.Name]);
  75. //}
  76. }
  77. }
  78. private void pictureBox_MouseLeave(object sender, EventArgs e)
  79. {
  80. if (!this.DesignMode)
  81. {
  82. PictureBox box = (PictureBox)sender;
  83. //MessageBox.Show(defaultPicture.Name + ":" + box.Name);
  84. //if (defaultPicture.Name != box.Name)
  85. //{
  86. // box.Image = Image.FromFile(mouseLeaveDic[box.Name]);
  87. //}
  88. }
  89. }
  90. public event EventHandler MyClick;
  91. private void pictureBox_Click(object sender, EventArgs e)
  92. {
  93. if (!this.DesignMode)
  94. {
  95. PictureBox box = (PictureBox)sender;
  96. MyClick(box.Name, e);
  97. DefaultPicture = box;
  98. }
  99. }
  100. public void StyleImgChange(string functionName)
  101. {
  102. if (functionName == "pictureBoxSYZ")
  103. {
  104. this.pictureBoxControl.Visible = false;
  105. }
  106. try
  107. {
  108. PictureBox picBox = (PictureBox)this.Controls.Find(functionName, true).FirstOrDefault();
  109. if (picBox != null)
  110. DefaultPicture = picBox;
  111. }
  112. catch (Exception ex)
  113. {
  114. logger.Info("标题切换失败" + ex.Message);
  115. }
  116. }
  117. }
  118. }