[英]Moving image on windows form
Is it possible to make image, which is 'standing' still, move when I hover with my mouse over the image? 当我将鼠标悬停在图像上时,是否可以使“静止”的图像移动? I'm working in vs 2012, c# and win forms and I want simple movement like gif image, something similar to that, just to make it 'alive'
我正在使用vs 2012,c#和win形式工作,我想要简单的动作,例如gif图像,类似的东西,只是为了使其“活跃”
And how to make that? 以及如何做到这一点? Thank you very much
非常感谢你
It is - you can alter the Picturebox.Location like that. 是的-您可以像这样更改Picturebox.Location。 Note that this is an illustration and some edge cases may exist - for example you may want to add logic that detects when the image moved so much, that mouse went out (but within the original 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.