MouseMove causes Flicker

aziz rasul

Active member
Local time
Today, 16:01
Joined
Jun 26, 2000
Messages
1,935
I have a textbox on a form. The form also contains two subforms (call them subform1 and subform2) superimposed over each other. subform1 is the subform that is normally visible.

On the MouseMove event, when I hover the mouse cursor over the textbox, I want sunform1 to become invisible and subform2 to become visible depending on the value of the textbox. This is the code I have which works.

Code:
Private Sub txtReferralID_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    
    If Me.txtreferralid > 0 Then
        Me.subform2.Visible = True
        Me.subform1.Visible = False
        Me.subform2.Requery
    Else
        Me.subform2.Visible = False
        Me.subform1.Visible = True
    End If

End Sub

The problem that I have is that subform2 flickers when the mouse cursor is over the textbox. I know that it's because it carries out the MouseMove event over and over again, but how can I amend the code to get rid of this flicker?
 
I would suggest testing to see if is is already visible before setting it again.

Something like:

Code:
Private Sub txtReferralID_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    
    If Me.txtreferralid > 0 Then
      If Me.subform2.Visible = False Then         
            Me.subform2.Visible = True
            Me.subform1.Visible = False
            Me.subform2.Requery
      End If
    Else
      If Me.subform1.Visible = False Then 
            Me.subform2.Visible = False
            Me.subform1.Visible = True
      End If
    End If

End Sub
 
Boyd's right as to the solution.

Also consider implementing Event handling similar to how Chris describes in his FAQ at UA here - you'll need to join to view the attachment though - so perhaps look at this this thread which briefly explains the concept.
 
Thaanks both. It worked a treat.
Good idea to stop and start MouseEvents. I'll remember that in future and add it to my library of goodies.
 

Users who are viewing this thread

Back
Top Bottom