Reputation: 51
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'
And how to make that? Thank you very much
Upvotes: 0
Views: 3858
Reputation: 7783
It is - you can alter the Picturebox.Location like that. 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);
}
Upvotes: 1