繁体   English   中英

在Windows窗体上移动图像

[英]Moving image on windows form

当我将鼠标悬停在图像上时,是否可以使“静止”的图像移动? 我正在使用vs 2012,c#和win形式工作,我想要简单的动作,例如gif图像,类似的东西,只是为了使其“活跃”

以及如何做到这一点? 非常感谢你

是的-您可以像这样更改Picturebox.Location。 请注意,这只是一个示例,可能存在一些边缘情况-例如,您可能想添加逻辑以检测图像何时移动了太多,鼠标掉了(但在原始位置)

private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
    int x = pictureBox1.Location.X;
    int y = pictureBox1.Location.Y;
    pictureBox1.Location = new Point(x + 25, y + 15);
}

private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
    int x = pictureBox1.Location.X;
    int y = pictureBox1.Location.Y;
    pictureBox1.Location = new Point(x - 25, y - 15);
}

暂无
暂无

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

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