Hide or show a picturebox when mouse moves over another
My goal is to create this scenario:开发者_如何学编程
- if the mouse goes over picturebox1, then picturebox2 will show.
- if not over picturebox1, then picturebox2 won't show
How can I write C# code to perform this?
Simply use the MouseEnter and MouseLeave events:
private void pictureBox1_MouseEnter(object sender, EventArgs e) {
pictureBox2.Visible = true;
}
private void pictureBox1_MouseLeave(object sender, EventArgs e) {
pictureBox2.Visible = false;
}
you can use the MouseHover
event of PictureBox
...
In events of PictureBox1, there is a 'Mouse Hover Event'. Then, just put in:
PictureBox2.Show();
(I do visual basic, so it might be different for you, but It's very simple to fix. I figured it out in one of my previous projects.)
If you want it to show PictureBox2 as soon as the mouse touches PictureBox1, then put the command into another event labelled 'Mouse Enter'
To hide PictureBox2 when the mouse is NOT touching PictureBox1, do the 'Mouse Leave' event.
You can also make it so that if you keep your mouse off of PictureBox1 for too long and leaving it on the window, PictureBox2 will disappear. The event for this is in the Form you created, by selecting the window/form and adding the event 'Mouse Hover Event' and simply writing:
PictureBox2.Hide();
(Again, I'm using Visual Basic.)
I hope that this helps!!! ☺
精彩评论