Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MouseEnter and MouseLeave far too slow

Status
Not open for further replies.

j0em0mma

Programmer
Jul 31, 2003
131
US
I am trying to achieve hover effects in a windows forms application. I have a list of 19 or so items beside a summary box. When a user mouses over a menu item, it does several things:

1) Border is drawn around menu item and bg color set to white with a small alpha level.

2) an invisible connector line (1px tall picturebox) becomes visible connecting the menu item to the summary box.

3) The summary box has a Border drawn around it and bg color set to white with a small alpha level.

4) The summary text is changed from "" to the appropriate summary information.

Reverse this on MouseLeave.

Problem is, if you move the mouse normally, it doesn't register the mouseleave event as occurring, leaving the mouseenter state all over the place, showing incorrect summary data and just generally looking horrible. It only works properly at very slow speed. I have posted sample code below showing how I am doing this.

Code:
    'event pair

    Private Sub lblManageInventory_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblManageInventory.MouseEnter
        Menu_DHTML(True, Me.lblManageInventory, Me.lblHoverDescription, Me.pbxManageInventory)
        Me.lblHoverDescription.Text = "Available functionality: " & vbCrLf & vbCrLf & "Receive Inventory." & vbCrLf _
                                    & "Adjust Inventory." & vbCrLf _
                                    & "View Inventory Report." & vbCrLf
    End Sub

    Private Sub lblManageInventory_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblManageInventory.MouseLeave
        Menu_DHTML(False, Me.lblManageInventory, Me.lblHoverDescription, Me.pbxManageInventory)
        Me.lblHoverDescription.Text = ""
    End Sub

Code:
     'Called by event pair

    Private Sub Menu_DHTML(ByVal MouseEnter As Boolean, ByRef objMenuItem As System.Windows.Forms.Label, ByRef objHelpFrame As System.Windows.Forms.Label, ByRef objPBXLine As System.Windows.Forms.PictureBox)
        If MouseEnter Then
            objMenuItem.BackColor = Color.FromArgb(32, 255, 255, 255)
            objHelpFrame.BackColor = Color.FromArgb(32, 255, 255, 255)
            objMenuItem.BorderStyle = BorderStyle.FixedSingle
            objHelpFrame.BorderStyle = BorderStyle.FixedSingle
            objPBXLine.Visible = True
        Else
            objMenuItem.BackColor = Color.FromArgb(0, 255, 255, 255)
            objHelpFrame.BackColor = Color.FromArgb(0, 255, 255, 255)
            objMenuItem.BorderStyle = BorderStyle.None
            objHelpFrame.BorderStyle = BorderStyle.None
            objPBXLine.Visible = False
        End If

    End Sub

Is there a way to do this without the errors? Or, is there a faster method that would require the user to move the mouse much faster in order to generate the errors? Currently, the mouse must be moved at a speed far below the average user's mouse movement speed.

Thanks!
 
Try throwing in an Application.DoEvents right before the End Sub of the MouseEnter and MouseLeave event handlers. Maybe put one in at the end of Menu_DHTML as well.





I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Thx Jebenson,

I tried this out Application.DoEvents() at the end, then the beginning of each of my events plus the DHTML sub, no availe... though the Summary box did swap faster.

I actually tried publishing the app to make sure this wasn't a feature of the debugger. There is a lot of screen flicker in the debug mode and I thought it would clean up once compiled. Not so, it didn't speed up a pico-second... and of course, the mouseenter and mouseleave events are miserable...

The only other thing I can think to do is close ALL mutually exclusive visuals every time I run the DHTML subroutine, then just turn on the calling labels' and picturebox', but this seems grossly inelegant and tough to maintain.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top