using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using IntelligentControlForsx.Code; using log4net; namespace IntelligentControlForsx.MyControls { public partial class Title : UserControl { private ILog logger = LogManager.GetLogger("AppInfoLog"); /// /// 鼠标悬停取得图片路径 /// Dictionary mouseEnterDic = new Dictionary(); /// /// 鼠标离开取得图片路径 /// Dictionary mouseLeaveDic = new Dictionary(); /// /// 鼠标离开取得图片路径 /// //Dictionary pictureDic = new Dictionary(); /// /// 鼠标点击跳转页面地址 /// Dictionary mouseClickDic = new Dictionary(); string path = UserTools.Path; public Title() { InitializeComponent(); if (!this.DesignMode) { string homeStr = path + @"\images\导航1.png"; string matrixStr = path + @"\images\导航2.png"; string paramtersStr = path + @"\images\导航3.png"; string controlStr = path + @"\images\ZDQT1.png"; string mainParamStr = path + @"\images\导航5.png"; string statisticsStr = path + @"\images\导航6.png"; string faultStr = path + @"\images\导航7.png"; string electricalStr = path + @"\images\导航8.png"; string windturbineStr = path + @"\images\fj1.png"; string syzStr = path + @"\images\导航8.png"; string agcStr = path + @"\images\agc1.png"; string homeStr2 = path + @"\images\导航11.png"; string matrixStr2 = path + @"\images\导航12.png"; string paramtersStr2 = path + @"\images\导航13.png"; string controlStr2 = path + @"\images\ZDQT2.png"; string mainParamStr2 = path + @"\images\导航15.png"; string statisticsStr2 = path + @"\images\导航16.png"; string faultStr2 = path + @"\images\导航17.png"; string electricalStr2 = path + @"\images\导航18.png"; string windturbineStr2 = path + @"\images\fj11.png"; string syzStr2 = path + @"\images\导航18.png"; string agcStr2 = path + @"\images\agc11.png"; mouseLeaveDic.Add(this.pictureBoxHome.Name, homeStr); mouseLeaveDic.Add(this.pictureBoxMatrix.Name, matrixStr); mouseLeaveDic.Add(this.pictureBoxParamters.Name, paramtersStr); mouseLeaveDic.Add(this.pictureBoxControl.Name, controlStr); mouseLeaveDic.Add(this.pictureBoxMainParam.Name, mainParamStr); mouseLeaveDic.Add(this.pictureBoxStatistics.Name, statisticsStr); mouseLeaveDic.Add(this.pictureBoxElectrical.Name, electricalStr); mouseLeaveDic.Add(this.pictureBoxWindturbine.Name, windturbineStr); mouseLeaveDic.Add(this.pictureBoxSYZ.Name, syzStr); mouseLeaveDic.Add(this.pictureBoxAGC.Name, agcStr); mouseEnterDic.Add(this.pictureBoxHome.Name, homeStr2); mouseEnterDic.Add(this.pictureBoxMatrix.Name, matrixStr2); mouseEnterDic.Add(this.pictureBoxParamters.Name, paramtersStr2); mouseEnterDic.Add(this.pictureBoxControl.Name, controlStr2); mouseEnterDic.Add(this.pictureBoxMainParam.Name, mainParamStr2); mouseEnterDic.Add(this.pictureBoxStatistics.Name, statisticsStr2); mouseEnterDic.Add(this.pictureBoxElectrical.Name, electricalStr2); mouseEnterDic.Add(this.pictureBoxWindturbine.Name, windturbineStr2); mouseEnterDic.Add(this.pictureBoxSYZ.Name, syzStr2); mouseEnterDic.Add(this.pictureBoxAGC.Name, agcStr2); //pictureDic.Add(0, this.pictureBoxHome); //pictureDic.Add(1, this.pictureBoxMatrix); //pictureDic.Add(2, this.pictureBoxParamters); //pictureDic.Add(3, this.pictureBoxControl); //pictureDic.Add(4, this.pictureBoxMainParam); //pictureDic.Add(5, this.pictureBoxStatistics); //pictureDic.Add(6, this.pictureBoxFault); //pictureDic.Add(7, this.pictureBoxElectrical); this.pictureBoxHome.Cursor = System.Windows.Forms.Cursors.Hand; this.pictureBoxMatrix.Cursor = System.Windows.Forms.Cursors.Hand; this.pictureBoxParamters.Cursor = System.Windows.Forms.Cursors.Hand; this.pictureBoxControl.Cursor = System.Windows.Forms.Cursors.Hand; this.pictureBoxMainParam.Cursor = System.Windows.Forms.Cursors.Hand; this.pictureBoxStatistics.Cursor = System.Windows.Forms.Cursors.Hand; this.pictureBoxElectrical.Cursor = System.Windows.Forms.Cursors.Hand; this.pictureBoxWindturbine.Cursor = System.Windows.Forms.Cursors.Hand; this.pictureBoxSYZ.Cursor = System.Windows.Forms.Cursors.Hand; this.pictureBoxAGC.Cursor = System.Windows.Forms.Cursors.Hand; defaultPicture = this.pictureBoxHome; this.defaultPicture.Cursor = System.Windows.Forms.Cursors.Default; } } PictureBox defaultPicture; [Browsable(true), Category("Appearance")] public PictureBox DefaultPicture { get { return defaultPicture; } set { //if (pictureDic.ContainsKey(value)) //{ if (!this.DesignMode && defaultPicture != value) { value.Image = Image.FromFile(mouseEnterDic[value.Name]); value.Cursor = System.Windows.Forms.Cursors.Default; defaultPicture.Image = Image.FromFile(mouseLeaveDic[defaultPicture.Name]); defaultPicture.Cursor = System.Windows.Forms.Cursors.Hand; } defaultPicture = value; //} } } private void pictureBox_MouseEnter(object sender, EventArgs e) { if (!this.DesignMode) { PictureBox box = (PictureBox)sender; // MessageBox.Show(defaultPicture.Name + ":" + box.Name); if (defaultPicture.Name != box.Name) { box.Image = Image.FromFile(mouseEnterDic[box.Name]); } } } private void pictureBox_MouseLeave(object sender, EventArgs e) { if (!this.DesignMode) { PictureBox box = (PictureBox)sender; //MessageBox.Show(defaultPicture.Name + ":" + box.Name); if (defaultPicture.Name != box.Name) { box.Image = Image.FromFile(mouseLeaveDic[box.Name]); } } } public event EventHandler MyClick; private void pictureBox_Click(object sender, EventArgs e) { if (!this.DesignMode) { PictureBox box = (PictureBox)sender; if ("pictureBoxHome".Equals(box.Name) || defaultPicture.Name != box.Name) { if (MyClick == null) { MessageBox.Show(box.Name); } else { // MessageBox.Show(box.Name); MyClick(box.Name, e); DefaultPicture = box; } } else if (box.Name == "pictureBoxMatrix") { if (MyClick == null) { MessageBox.Show(box.Name); } else { // MessageBox.Show(box.Name); MyClick(box.Name, e); DefaultPicture = box; } } } } private void pictureBoxElectrical_Click(object sender, EventArgs e) { this.pictureBoxElectrical.Visible = false; this.pictureBoxMatrix.Visible = false; this.pictureBoxParamters.Visible = false; this.pictureBoxControl.Visible = false; this.pictureBoxMainParam.Visible = false; this.pictureBoxStatistics.Visible = false; this.pictureBoxSYZ.Visible = true; this.pictureBoxAGC.Visible = true; this.pictureBoxWindturbine.Visible = true; } private void pictureBoxWindturbine_Click(object sender, EventArgs e) { this.pictureBoxSYZ.Visible = false; this.pictureBoxAGC.Visible = false; this.pictureBoxWindturbine.Visible = false; this.pictureBoxElectrical.Visible = true; this.pictureBoxMatrix.Visible = true; this.pictureBoxParamters.Visible = true; this.pictureBoxControl.Visible = true; this.pictureBoxMainParam.Visible = true; this.pictureBoxStatistics.Visible = true; } public void StyleImgChange(string functionName) { if (functionName == "pictureBoxSYZ") { this.pictureBoxElectrical.Visible = false; this.pictureBoxMatrix.Visible = false; this.pictureBoxParamters.Visible = false; this.pictureBoxControl.Visible = false; this.pictureBoxMainParam.Visible = false; this.pictureBoxStatistics.Visible = false; this.pictureBoxSYZ.Visible = true; this.pictureBoxAGC.Visible = true; this.pictureBoxWindturbine.Visible = true; } try { PictureBox picBox = (PictureBox)this.Controls.Find(functionName, true).FirstOrDefault(); if (picBox != null) DefaultPicture = picBox; } catch (Exception ex) { logger.Info("标题切换失败" + ex.Message); } } // 鼠标进入移出 效果 private void title_main_MouseEnter(object sender, EventArgs e) { } } }