[RESOLVED] Issue with MouseLeave event
I'm wanting to create an effect where the user knows when they're hovering over a picturebox, but I don't want to use the MouseHover event because with the Hover event you have to wait a bit of time for it to fire, where I need it immediately. What I'm currently doing is setting the BorderStyle in the MouseEnter/Leave events. The issue comes with the MouseLeave event, it doesn't always set the BorderStyle back to none. The way I'm loading the pictureboxes is like so:
Code:
For x As Integer = 0 To board_size.Width - 1
For y As Integer = 0 To board_size.Height - 1
Dim pb As New PictureBox
With pb
.BackColor = Color.White
.Location = New Point(x * 50, y * 50)
.Size = New Size(50, 50)
.SizeMode = PictureBoxSizeMode.Zoom
.BorderStyle = BorderStyle.None
End With
AddHandler pb.MouseEnter, AddressOf board_MouseEnter
AddHandler pb.MouseLeave, AddressOf board_MouseLeave
board(x, y) = pb
SplitContainer1.Panel2.Controls.Add(pb)
Next
Next
The MouseEnter/Leave look like this:
Code:
Private Sub board_MouseEnter(sender As Object, e As EventArgs)
Dim pb As PictureBox = DirectCast(sender, PictureBox)
pb.BorderStyle = BorderStyle.FixedSingle
End Sub
Private Sub board_MouseLeave(sender As Object, e As EventArgs)
Dim pb As PictureBox = DirectCast(sender, PictureBox)
pb.BorderStyle = BorderStyle.None
End Sub
Is there any reason why the borderstyle isn't being set to none?
Re: Issue with MouseLeave event
I don't trust it.
One thing I would do would be to write up some kind of minor logging. This could be as simple as a List (of String), since you wouldn't need anything other than the memory record. I'd then log these three events: Enter, Leave, and Move. I'd then try slowly moving the mouse into, then out of, the control. Next I would try moving fast into the control, over to another control, then away. What I would be looking for would be a pattern of when things fire and when they do not. I would expect that you would see such a pattern. After all, those three events do have some real peculiarities to them. I have a thread on here somewhere where I was puzzled over the fact that changing the text in a tooltip triggers a mouse move event. It is also clear that mouse move events don't always happen. I expect that you will be able to find specific circumstances where the enter and leave events don't happen, as well.
Re: Issue with MouseLeave event
Did you try just using the PictureBox Mouse Enter and Mouse Leave events directly ?
i.e. When in Form1.vb [Design] view: Click PictureBox1 (Select it) then in the Properties Dialogue click the 'Lightning Strike' Icon: go down the list and find and click: MouseEnter. This will give you the code stub for the event, do the same for MouseLeave.
Poppa.
Re: Issue with MouseLeave event
Quote:
Originally Posted by
Poppa Mintin
Did you try just using the PictureBox Mouse Enter and Mouse Leave events directly ?
i.e. When in Form1.vb [Design] view: Click PictureBox1 (Select it) then in the Properties Dialogue click the 'Lightning Strike' Icon: go down the list and find and click: MouseEnter. This will give you the code stub for the event, do the same for MouseLeave.
Poppa.
I'm unable to do that because I create the PictureBoxes dynamically.
Quote:
I'd then log these
I logged the Enter and Leave because when I logged the Move it quadrupled the textfile size. Here are the results:
Quote:
'Slow
MouseEnter: PictureBoxX:0Y:0
MouseLeave: PictureBoxX:0Y:0
MouseEnter: PictureBoxX:0Y:0
MouseEnter: PictureBoxX:1Y:0
MouseLeave: PictureBoxX:1Y:0
MouseEnter: PictureBoxX:1Y:0
MouseEnter: PictureBoxX:2Y:0
MouseLeave: PictureBoxX:2Y:0
MouseEnter: PictureBoxX:2Y:0
MouseEnter: PictureBoxX:3Y:0
MouseLeave: PictureBoxX:3Y:0
MouseEnter: PictureBoxX:3Y:0
MouseEnter: PictureBoxX:4Y:0
MouseLeave: PictureBoxX:4Y:0
MouseEnter: PictureBoxX:4Y:0
MouseEnter: PictureBoxX:5Y:0
MouseLeave: PictureBoxX:5Y:0
MouseEnter: PictureBoxX:6Y:0
MouseLeave: PictureBoxX:6Y:0
MouseEnter: PictureBoxX:6Y:0
MouseEnter: PictureBoxX:6Y:1
MouseLeave: PictureBoxX:6Y:1
MouseEnter: PictureBoxX:6Y:1
MouseEnter: PictureBoxX:5Y:1
MouseLeave: PictureBoxX:5Y:1
MouseEnter: PictureBoxX:5Y:1
MouseEnter: PictureBoxX:4Y:1
MouseLeave: PictureBoxX:4Y:1
MouseEnter: PictureBoxX:4Y:1
MouseEnter: PictureBoxX:3Y:1
MouseLeave: PictureBoxX:3Y:1
MouseEnter: PictureBoxX:3Y:1
MouseEnter: PictureBoxX:2Y:1
MouseLeave: PictureBoxX:2Y:1
MouseEnter: PictureBoxX:2Y:1
MouseEnter: PictureBoxX:1Y:1
MouseLeave: PictureBoxX:1Y:1
MouseEnter: PictureBoxX:1Y:1
MouseEnter: PictureBoxX:0Y:1
MouseLeave: PictureBoxX:0Y:1
MouseEnter: PictureBoxX:0Y:1
'Fast
MouseEnter: PictureBoxX:0Y:2
MouseLeave: PictureBoxX:0Y:2
MouseEnter: PictureBoxX:0Y:2
MouseEnter: PictureBoxX:1Y:2
MouseLeave: PictureBoxX:1Y:2
MouseEnter: PictureBoxX:2Y:2
MouseLeave: PictureBoxX:2Y:2
MouseEnter: PictureBoxX:3Y:2
MouseLeave: PictureBoxX:3Y:2
MouseEnter: PictureBoxX:4Y:2
MouseLeave: PictureBoxX:4Y:2
MouseEnter: PictureBoxX:4Y:2
MouseEnter: PictureBoxX:5Y:2
MouseLeave: PictureBoxX:5Y:2
MouseEnter: PictureBoxX:5Y:2
MouseEnter: PictureBoxX:6Y:2
MouseLeave: PictureBoxX:6Y:2
MouseEnter: PictureBoxX:6Y:2
MouseEnter: PictureBoxX:6Y:3
MouseLeave: PictureBoxX:6Y:3
MouseEnter: PictureBoxX:6Y:3
MouseEnter: PictureBoxX:5Y:3
MouseLeave: PictureBoxX:5Y:3
MouseEnter: PictureBoxX:4Y:3
MouseLeave: PictureBoxX:4Y:3
MouseEnter: PictureBoxX:3Y:3
MouseLeave: PictureBoxX:3Y:3
MouseEnter: PictureBoxX:2Y:3
MouseLeave: PictureBoxX:2Y:3
MouseEnter: PictureBoxX:1Y:3
MouseLeave: PictureBoxX:1Y:3
MouseEnter: PictureBoxX:1Y:3
MouseEnter: PictureBoxX:0Y:3
MouseLeave: PictureBoxX:0Y:3
MouseEnter: PictureBoxX:0Y:4
MouseLeave: PictureBoxX:0Y:4
MouseEnter: PictureBoxX:0Y:4
MouseEnter: PictureBoxX:1Y:4
MouseLeave: PictureBoxX:1Y:4
MouseEnter: PictureBoxX:2Y:4
MouseLeave: PictureBoxX:2Y:4
MouseEnter: PictureBoxX:3Y:4
MouseLeave: PictureBoxX:3Y:4
MouseEnter: PictureBoxX:4Y:4
MouseLeave: PictureBoxX:4Y:4
MouseEnter: PictureBoxX:5Y:4
MouseLeave: PictureBoxX:5Y:4
MouseEnter: PictureBoxX:6Y:4
MouseLeave: PictureBoxX:6Y:4
The issue came when the mouse moved slowly. The pattern appears to be that the MouseLeave event gets fired before the MouseEnter event some how. It's very strange.
Re: Issue with MouseLeave event
in addition to the mouseleave code for each individual picturebox, in your mouseenter code change the borderstyle to BorderStyle.None for all other pictureboxes on the form before setting that picturebox borderstyle = BorderStyle.FixedSingle
Re: Issue with MouseLeave event
Well .paul. as simple as that is, it works perfectly. I don't know why I didn't do that in the first place! Thanks to all of you.
Re: [RESOLVED] Issue with MouseLeave event
That log makes it look like those events really aren't all that reliable, which is what I have always suspected.
Re: [RESOLVED] Issue with MouseLeave event
I tried this with 3 picture boxes
Code:
Private Sub PictureBox_MouseEnter(sender As Object, e As EventArgs) _
Handles PictureBox1.MouseEnter, PictureBox2.MouseEnter, PictureBox3.MouseEnter
Dim pb As PictureBox = DirectCast(sender, PictureBox)
pb.BorderStyle = BorderStyle.FixedSingle
End Sub
Private Sub PictureBox_MouseLeave(sender As Object, e As EventArgs) _
Handles PictureBox1.MouseLeave, PictureBox2.MouseLeave, PictureBox3.MouseLeave
Dim pb As PictureBox = DirectCast(sender, PictureBox)
pb.BorderStyle = BorderStyle.None
End Sub
and did not reproduce the OP's problem.
edit: after playing with this a little more I did reproduce. Very odd!
Re: [RESOLVED] Issue with MouseLeave event
@dbasnett, I believe it's because I was doing it with about 50+- pictureboxes.
Re: [RESOLVED] Issue with MouseLeave event
Quote:
Originally Posted by
dday9
@dbasnett, I believe it's because I was doing it with about 50+- pictureboxes.
I edited my previous post to acknowledge that that the error occurs.
Re: [RESOLVED] Issue with MouseLeave event
I filled out a bug report for this. The bug ID is 789658.
Re: [RESOLVED] Issue with MouseLeave event
Ok cool, I've never had to report a bug with VS before so I'm glad you did it!
Re: [RESOLVED] Issue with MouseLeave event
I tried this with just one picture box, and by slowly moving the mouse off of the picture box the code also fails.
Re: [RESOLVED] Issue with MouseLeave event
Re: [RESOLVED] Issue with MouseLeave event
what is happening here?
every time I click on dbasnett's link the link jumps away from my mouse...
Re: [RESOLVED] Issue with MouseLeave event
Quote:
Originally Posted by
.paul.
what is happening here?
every time I click on dbasnett's link the link jumps away from my mouse...
What?
2 Attachment(s)
Re: [RESOLVED] Issue with MouseLeave event
Re: [RESOLVED] Issue with MouseLeave event
Quote:
Originally Posted by
.paul.
It works for me. Wonder if others have the same issue.
Re: [RESOLVED] Issue with MouseLeave event
If you reverse the borders it seems to work.
Code:
Private Sub PictureBox_MouseEnter(sender As Object, e As EventArgs) _
Handles PictureBox1.MouseEnter, PictureBox2.MouseEnter, PictureBox3.MouseEnter
Dim pb As PictureBox = DirectCast(sender, PictureBox)
'pb.BorderStyle = BorderStyle.FixedSingle
pb.BorderStyle = BorderStyle.None '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
' Debug.WriteLine("E " & pb.Name)
End Sub
Private Sub PictureBox_MouseLeave(sender As Object, e As EventArgs) _
Handles PictureBox1.MouseLeave, PictureBox2.MouseLeave, PictureBox3.MouseLeave
Dim pb As PictureBox = DirectCast(sender, PictureBox)
'pb.BorderStyle = BorderStyle.None
pb.BorderStyle = BorderStyle.FixedSingle '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
' Debug.WriteLine("X " & pb.Name)
End Sub
Re: [RESOLVED] Issue with MouseLeave event
Posted by Microsoft on 6/10/2013 at 4:06 PM
Quote:
Thank you for reporting this issue. Customer feedback is a critical part of a successful, impactful software product. Unfortunately another part is the reality of schedules and the need to prioritize investments according to the objectives of the product. We have evaluated the issue that you have reported and at this point in the product's lifecycle, it does not meet the criteria to be addressed. This evaluation is carefully done and considers many aspects including the cost of the fix, implications of the change, and the number of reported instances of the issue.
Many customers have found it useful to discuss issues like this in the forums (
http://www.microsoft.com/communities...s/default.mspx) where Microsoft and other members of the community can recommend ways of achieving the behavior you are interested in.
Thank you,
The Windows Forms Product Team
Re: [RESOLVED] Issue with MouseLeave event