[英]Change background image of PictureBox on mouseover in C#?
How can I change the background image of a PicureBox when I hover my mouse over it in C#? 当我将鼠标悬停在C#中时,如何更改PicureBox的背景图像? I'm using visual c# 2010 Express.
我正在使用Visual C#2010 Express。 Thanks
谢谢
You just need to subscribe to MouseHover Event an change Image Property. 您只需要向MouseHover Event订阅一个更改Image属性。
This should do the trick: 这应该可以解决问题:
PictureBox o = new PictureBox();
o.MouseHover += (a_sender, a_args) =>
{
PictureBox pic = a_sender as PicureBox;
pic.Image = null // New Image..
};
Again when you need to restore previous picture use: MouseLeave
再次需要恢复以前的图片时使用:
MouseLeave
On PictureBox properties, double click on event MouseEnter and use: 在PictureBox属性上,双击事件MouseEnter并使用:
(sender as PictureBox).Image = Image.FromFile(// path of image1);
then double click on event MouseLeave and use: 然后双击事件MouseLeave并使用:
(sender as PictureBox).Image = Image.FromFile(// path of image2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.