简体   繁体   English

C# MetroTile 背景色/前景色在鼠标进入/离开期间不会改变

[英]C# MetroTile backcolor/forecolor not changing during mouse enter/leave

I'm using the Win Form Metro Framework in VS 2015 to build a Metro Form with Metro Tiles in Windows 7. When a mouse enters a metro Tile I want the backcolor and forecolor to change and when the mouse leaves, change back.我在 VS 2015 中使用 Win Form Metro Framework 在 Windows 7 中使用 Metro Tiles 构建 Metro Form。当鼠标进入 Metro Tile 时,我希望背景色和前景色发生变化,当鼠标离开时,改回来。 However, it's not working.但是,它不起作用。 Nothing happens and I don't know what I'm doing wrong.什么也没发生,我不知道我做错了什么。

In the Form1.cs(Design) file I have set the following properties of all tiles to the following:在 Form1.cs(Design) 文件中,我将所有磁贴的以下属性设置为以下内容:

BackColor = White
ForeColor = Black
Name = caseCompassDevo
CustomBackground = True
CustomForeColor = True 

in the Form1.Designer.cs file I have the following code in the InitializeComponent() method:在 Form1.Designer.cs 文件中,我在 InitializeComponent() 方法中有以下代码:

// caseCompassDevo
        // 
        this.caseCompassDevo.BackColor = System.Drawing.Color.White;
        this.caseCompassDevo.CustomBackground = true;
        this.caseCompassDevo.CustomForeColor = true;
        this.caseCompassDevo.ForeColor = System.Drawing.Color.Black;
        this.caseCompassDevo.Location = new System.Drawing.Point(23, 92);
        this.caseCompassDevo.Name = "caseCompassDevo";
        this.caseCompassDevo.Size = new System.Drawing.Size(149, 87);
        this.caseCompassDevo.TabIndex = 0;
        this.caseCompassDevo.Text = "Case Compass DEVO";
        this.caseCompassDevo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
        this.caseCompassDevo.Click += new System.EventHandler(this.caseCompassDevo_Click);
        this.caseCompassDevo.MouseEnter += new System.EventHandler(this.caseCompassDevo_MouseEnter);
        this.caseCompassDevo.MouseLeave += new System.EventHandler(this.caseCompassDevo_MouseLeave);
//

in my Form1.cs file I have added the following events:在我的 Form1.cs 文件中,我添加了以下事件:

namespace Links
{
    public partial class Form1 : MetroFramework.Forms.MetroForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void caseCompassDevo_MouseEnter(object sender, EventArgs e)
        {
            BackColor = System.Drawing.Color.FromArgb(0, 174, 219); //MetroUI blue
            ForeColor = System.Drawing.Color.FromArgb(255, 255, 255); //white
        }

        private void caseCompassDevo_MouseLeave(object sender, EventArgs e)
        {
            BackColor = System.Drawing.Color.FromArgb(255, 255, 255); //white
            ForeColor = System.Drawing.Color.FromArgb(0, 0, 0);  //black
        }       

        private void caseCompassDevo_Click(object sender, EventArgs e)
        {

        }

        //private void caseCompassTest_MouseHover(object sender, EventArgs e)
        //{
        //}
    }
}

You should apply it to your caseCompassDevo .您应该将其应用于您的caseCompassDevo use BackColor property of caseCompassDevo and assign your appropriate color to that.使用 caseCompassDevo 的 BackColor 属性并为其分配适当的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM