首页 > 解决方案 > 如何创建效果:鼠标悬停在 C# Winform 中的按钮上时按钮亮起

问题描述

我用 C# Winform 创建了一个应用程序,类似:Window Media Player。当鼠标悬停在按钮上时,我不知道在应用程序媒体媒体播放器中创建灯光按钮是什么。

在此处输入图像描述

标签: c#winforms

解决方案


您可以使用两个图像。一张用于普通按钮,一张用于悬停按钮状态。从工具箱中拖动按钮控件,将FlatStyle设置为Popup

创建button.MouseEnterbutton.MouseLeave事件。

// Let's say you have images stores in resource file..
private static readonly Image image1 = Resources.button1;
private static readonly Image image2 = Resources.button2;
...
button1.MouseEnter += (s,e) => button1.Image = image2;
// And revert back
button1.MouseLeave += (s,e) => button1.Image = image1;

在此处输入图像描述


推荐阅读