繁体   English   中英

如何创建效果:在C#Winform中将鼠标悬停在按钮上时点亮按钮

[英]How to create effect: light button when mouse over button in C# Winform

我已经用C#Winform创建了一个应用程序,类似于:Window Media Player。 当鼠标悬停在按钮上时,我不知道如何在应用程序Media Media Player中创建灯光按钮。

在此处输入图片说明

您可以使用两个图像。 一幅用于普通按钮,一幅图像用于悬停按钮状态。 从工具箱中拖动按钮控件,将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;

在此处输入图片说明

在按钮的Mouse_Enter事件上,更改按钮的背景图像,然后将其更改回Mouse_Leave。

private Image cachedImage = Image.FromFile(@"C:\mouseOver.jpg");

...

button1.BackgroundImage = cachedImage;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM