鼠标进入/离开期间C#MetroTile backcolor / forecolor不会改变

时间:2016-09-15 19:42:41

标签: c# winforms

我正在使用VS 2015中的Win Form Metro Framework在Windows 7中使用Metro Tiles构建Metro表单。当鼠标进入地铁Tile时,我希望背景颜色和前景颜色发生变化,当鼠标离开时,请更改回来。但是,它不起作用。什么都没发生,我不知道我做错了什么。

在Form1.cs(设计)文件中,我将所有切片的以下属性设置为:

BackColor = White
ForeColor = Black
Name = caseCompassDevo
CustomBackground = True
CustomForeColor = True 
在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);
//

在我的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)
        //{
        //}
    }
}

1 个答案:

答案 0 :(得分:2)

您应该将其应用于caseCompassDevo。使用caseCompassDevo的BackColor属性并为其指定适当的颜色。