更改按钮文字颜色

时间:2016-07-08 08:57:38

标签: c# winforms

当我们将鼠标移到按钮上时,我们可以使用MouseOverBackColorMouseDownBackColor使用FlatApearance属性框更改按钮颜色。

当鼠标经过时,如何在同一模式下更改按钮文字颜色?

3 个答案:

答案 0 :(得分:3)

这适用于各种Buttons,有或没有FlatAppearance

private void button1_MouseEnter(object sender, EventArgs e)
{
    button1.ForeColor = Color.Red;
}

private void button1_MouseLeave(object sender, EventArgs e)
{
    button1.ForeColor = SystemColors.ControlText;

}

答案 1 :(得分:1)

如果您只想在鼠标悬停在按钮上时更改按钮文字颜色:

private void button1_MouseEnter(object sender, EventArgs e)
{
    button1.ForeColor = System.Drawing.Color.Red;
}

private void button1_MouseLeave(object sender, EventArgs e)
{
    button1.ForeColor = System.Drawing.Color.Black;
}

答案 2 :(得分:1)

使用 RGB 值,可能如下所示:

//Hover Text Color changing
    private void btnHome_MouseHover(object sender, EventArgs e)
    {
        btnHome.ForeColor = System.Drawing.Color.FromArgb(1, 102, 207);
    }

    private void btnHome_MouseLeave(object sender, EventArgs e)
    {
        btnHome.ForeColor = System.Drawing.Color.LightGray;
    }

不要忘记每次为每个按钮调用一个新方法!

按照这个图来找到一个很好的解决方案: enter image description here

enter image description here