在我用C#编写的Windows窗体应用程序中,有许多按钮。当用户将鼠标悬停在按钮上时,我希望按钮的边框发生变化。
目前,我有多个这样的实例(每个按钮都有一份):
目前,我有多个这样的实例(每个按钮都有一份):
private void btnStopServer_MouseEnter(object sender, EventArgs e)
{
oldColor = btnStopServer.FlatAppearance.BorderColor;
btnStopServer.FlatAppearance.BorderColor = mouseOverColor;
}
private void btnStopServer_MouseLeave(object sender, EventArgs e)
{
btnStopServer.FlatAppearance.BorderColor = oldColor;
}
由于我有很多按钮,改变按钮边框颜色的代码占用了很多空间。
有没有更简单的方法可以做到这一点?