Results 1 to 21 of 21

Thread: [RESOLVED] Issue with MouseLeave event

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,712

    Resolved [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?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    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.
    My usual boring signature: Nothing

  3. #3
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    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.
    Along with the sunshine there has to be a little rain sometime.

  4. #4

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,712

    Re: Issue with MouseLeave event

    Quote Originally Posted by Poppa Mintin View Post
    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.

    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:

    '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.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    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

  6. #6

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,712

    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.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    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.
    My usual boring signature: Nothing

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    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!
    Last edited by dbasnett; Jun 6th, 2013 at 01:46 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,712

    Re: [RESOLVED] Issue with MouseLeave event

    @dbasnett, I believe it's because I was doing it with about 50+- pictureboxes.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  10. #10
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: [RESOLVED] Issue with MouseLeave event

    Quote Originally Posted by dday9 View Post
    @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.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: [RESOLVED] Issue with MouseLeave event

    I filled out a bug report for this. The bug ID is 789658.
    Last edited by dbasnett; Jun 6th, 2013 at 03:35 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  12. #12

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,712

    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!
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  13. #13
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    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.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  14. #14
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  15. #15
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    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...

  16. #16
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: [RESOLVED] Issue with MouseLeave event

    Quote Originally Posted by .paul. View Post
    what is happening here?
    every time I click on dbasnett's link the link jumps away from my mouse...
    What?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  17. #17
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [RESOLVED] Issue with MouseLeave event

    your link:

    Name:  09-06-2013 01.47.29.jpg
Views: 2883
Size:  41.4 KB

    on clicking it:

    Name:  09-06-2013 01.48.01.jpg
Views: 2793
Size:  39.9 KB

  18. #18
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: [RESOLVED] Issue with MouseLeave event

    Quote Originally Posted by .paul. View Post
    your link:

    Name:  09-06-2013 01.47.29.jpg
Views: 2883
Size:  41.4 KB

    on clicking it:

    Name:  09-06-2013 01.48.01.jpg
Views: 2793
Size:  39.9 KB
    It works for me. Wonder if others have the same issue.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  19. #19
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  20. #20
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: [RESOLVED] Issue with MouseLeave event

    Posted by Microsoft on 6/10/2013 at 4:06 PM
    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

    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  21. #21

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,712

    Re: [RESOLVED] Issue with MouseLeave event

    All about the money.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width