对于我的应用程序,我想在悬停在图像链接上时显示漂亮的"手指"图像.
我这样做了;
//MouseHover Event
this.Cursor = Cursors.Hand;
Run Code Online (Sandbox Code Playgroud)
然而,效果持续存在并且光标保持为指向手指.
为了解决这个问题我实现了一个MouseHover和MouseLeave解决方案,以恢复光标恢复正常.
//MouseLeave Event
this.Cursor = Cursors.Default;
Run Code Online (Sandbox Code Playgroud)
完善!不太好,我现在必须为我表单上的每个链接制作这两个事件.有没有更快的方法来执行此操作,将规则应用于所有链接(或链接集合)?
使用链接为PictureBoxes创建自定义控件.覆盖OnMouseEnter和OnMouseLeave方法:
public class PictureBoxLink : PictureBox
{
protected override void OnMouseEnter(EventArgs e)
{
Cursor = Cursors.Hand;
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
Cursor = Cursors.Default;
base.OnMouseLeave(e);
}
}
Run Code Online (Sandbox Code Playgroud)
并使用它而不是标准PictureBox控制.