winform设置鼠标指向按钮时的背景图片
您可以使用MouseEnter和MouseLeave事件来更改按钮的背景图片。在MouseEnter事件中,更改按钮的背景图片为指向状态的图片,在MouseLeave事件中,更改按钮的背景图片为普通状态的图片。
以下是一个示例代码:
private void button1_MouseEnter(object sender, EventArgs e) { button1.BackgroundImage = Properties.Resources.hoverImage; }
private void button1_MouseLeave(object sender, EventArgs e) { button1.BackgroundImage = Properties.Resources.normalImage; }
请注意,您需要在项目资源中添加两个背景图片,并将它们命名为“hoverImage”和“normalImage”。
原文地址: https://www.cveoy.top/t/topic/hrLV 著作权归作者所有。请勿转载和采集!