当我们将鼠标移到按钮上时,我们可以使用MouseOverBackColor
和MouseDownBackColor
使用FlatApearance
属性框更改按钮颜色。
当鼠标经过时,如何在同一模式下更改按钮文字颜色?
答案 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;
}
不要忘记每次为每个按钮调用一个新方法!