Problem with font changing using mouse move event (1 Viewer)

jjake

Registered User.
Local time
Today, 14:00
Joined
Oct 8, 2015
Messages
291
I am using the following code to change numerous images/text/buttons on my home navigation screen from white to orange when they are highlighted and then returned to white when the mouse is moved back over the background that is behind/ separates the boxes.

Code:
Private Sub ButMOC_Click()
Me.tabMOC.SetFocus
End Sub

Private Sub butPI_Click()
Me.TabPlantInfo.SetFocus
End Sub

Private Sub butPI_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    FontOrange = RGB(237, 125, 49)

If Not Me!arr1.ForeColor = FontOrange Then
Me!arr1.ForeColor = FontOrange
Me!cmdPI.ForeColor = FontOrange
Me!ImgPIOn.Visible = True

End If
End Sub

Private Sub butPM_Click()
Me.TabPM.SetFocus
End Sub

Private Sub butPM_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    FontOrange = RGB(237, 125, 49)
    
If Not Me!arr2.ForeColor = FontOrange Then
Me!arr2.ForeColor = FontOrange
Me!cmdPM.ForeColor = FontOrange
Me!ImgPMOn.Visible = True

End If
End Sub

Private Sub butPur_Click()
Me.TabPur.SetFocus
End Sub

Private Sub butWO_Click()
Me.TabWO.SetFocus
End Sub

Private Sub butWO_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    FontOrange = RGB(237, 125, 49)
    
If Not Me!arr3.ForeColor = FontOrange Then
Me!arr3.ForeColor = FontOrange
Me!cmdWO.ForeColor = FontOrange
Me!imgWOOn.Visible = True

End If
End Sub



Private Sub ButPro_Click()

Me.TabPro.SetFocus
End Sub

Private Sub ButAdm_Click()

Me.TabAdm.SetFocus
End Sub

Private Sub ButUpd_Click()

Me.Tabupd.SetFocus
End Sub




Private Sub butMOC_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    FontOrange = RGB(237, 125, 49)
    
If Not Me!arr4.ForeColor = FontOrange Then
Me!arr4.ForeColor = FontOrange
Me!cmdMOC.ForeColor = FontOrange
Me!imgMOCOn.Visible = True

End If
End Sub

Private Sub ButPUR_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    FontOrange = RGB(237, 125, 49)
    
If Not Me!arr5.ForeColor = FontOrange Then
Me!arr5.ForeColor = FontOrange
Me!cmdPur.ForeColor = FontOrange
Me!imgPurOn.Visible = True

End If
End Sub

Private Sub ButPro_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    FontOrange = RGB(237, 125, 49)
    
If Not Me!arr6.ForeColor = FontOrange Then
Me!arr6.ForeColor = FontOrange
Me!cmdPro.ForeColor = FontOrange
Me!ImgproOn.Visible = True

End If
End Sub

Private Sub ButAdm_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    FontOrange = RGB(237, 125, 49)
    
If Not Me!arr7.ForeColor = FontOrange Then
Me!arr7.ForeColor = FontOrange
Me!cmdAdm.ForeColor = FontOrange
Me!imgadmOn.Visible = True

End If
End Sub

Private Sub ButUpd_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    FontOrange = RGB(237, 125, 49)
    
If Not Me!arr8.ForeColor = FontOrange Then
Me!arr8.ForeColor = FontOrange
Me!cmdUpd.ForeColor = FontOrange
Me!imgUpdOn.Visible = True


End If
End Sub

Private Sub Box5_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    FontWhite = RGB(255, 255, 255)

If Not Me!arr1.ForeColor = FontWhite Then
Me!arr1.ForeColor = FontWhite
Me!cmdPI.ForeColor = FontWhite
Me!ImgPIOn.Visible = False
End If

If Not Me!arr2.ForeColor = FontWhite Then
Me!arr2.ForeColor = FontWhite
Me!cmdPM.ForeColor = FontWhite
Me!ImgPMOn.Visible = False
End If

If Not Me!arr3.ForeColor = FontWhite Then
Me!arr3.ForeColor = FontWhite
Me!cmdWO.ForeColor = FontWhite
Me!imgWOOn.Visible = False
End If

If Not Me!arr4.ForeColor = FontWhite Then
Me!arr4.ForeColor = FontWhite
Me!cmdMOC.ForeColor = FontWhite
Me!imgMOCOn.Visible = False
End If

If Not Me!arr5.ForeColor = FontWhite Then
Me!arr5.ForeColor = FontWhite
Me!cmdPur.ForeColor = FontWhite
Me!imgPurOn.Visible = False
End If

If Not Me!arr6.ForeColor = FontWhite Then
Me!arr6.ForeColor = FontWhite
Me!cmdPro.ForeColor = FontWhite
Me!ImgproOn.Visible = False
End If

If Not Me!arr7.ForeColor = FontWhite Then
Me!arr7.ForeColor = FontWhite
Me!cmdAdm.ForeColor = FontWhite
Me!imgadmOn.Visible = False
End If

If Not Me!arr8.ForeColor = FontWhite Then
Me!arr8.ForeColor = FontWhite
Me!cmdUpd.ForeColor = FontWhite
Me!imgUpdOn.Visible = False
End If


End Sub

Private Sub Command92_Click()
Me.TabPlantInfo.SetFocus
End Sub

Private Sub Command92_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    FontOrange = RGB(237, 125, 49)

If Not Me!arr1.ForeColor = FontOrange Then
Me!arr1.ForeColor = FontOrange
Me!ImgPIOn.Visible = True
Me!cmdPI.ForeColor = FontOrange

End If
End Sub

Private Sub Command95_Click()

End Sub

Private Sub Form_Load()

Me.Move 0, 0

End Sub

Private Sub Image67_Click()
'Me.TabHome.SetFocus

DoCmd.OpenForm "home screen"
End Sub


Private Sub MainTabctl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    FontWhite = RGB(255, 255, 255)

If Not Me!arr1.ForeColor = FontWhite Then
Me!arr1.ForeColor = FontWhite
Me!cmdPI.ForeColor = FontWhite
Me!ImgPIOn.Visible = False
End If

If Not Me!arr2.ForeColor = FontWhite Then
Me!arr2.ForeColor = FontWhite
Me!cmdPM.ForeColor = FontWhite
Me!ImgPMOn.Visible = False
End If

If Not Me!arr3.ForeColor = FontWhite Then
Me!arr3.ForeColor = FontWhite
Me!cmdWO.ForeColor = FontWhite
Me!imgWOOn.Visible = False
End If

If Not Me!arr4.ForeColor = FontWhite Then
Me!arr4.ForeColor = FontWhite
Me!cmdMOC.ForeColor = FontWhite
Me!imgMOCOn.Visible = False
End If

If Not Me!arr5.ForeColor = FontWhite Then
Me!arr5.ForeColor = FontWhite
Me!cmdPur.ForeColor = FontWhite
Me!imgPurOn.Visible = False
End If

If Not Me!arr6.ForeColor = FontWhite Then
Me!arr6.ForeColor = FontWhite
Me!cmdPro.ForeColor = FontWhite
Me!ImgproOn.Visible = False
End If

If Not Me!arr7.ForeColor = FontWhite Then
Me!arr7.ForeColor = FontWhite
Me!cmdAdm.ForeColor = FontWhite
Me!imgadmOn.Visible = False
End If

If Not Me!arr8.ForeColor = FontWhite Then
Me!arr8.ForeColor = FontWhite
Me!cmdUpd.ForeColor = FontWhite
Me!imgUpdOn.Visible = False
End If


End Sub

I'm sure there was a cleaner way to do this but i am a novice when it comes to VBA.

My problem is that if i swipe my mouse fast enough between the text boxes i can make multiple of them change color, until i slowly move my mouse over the background. Is there a way to speed up this response time? or another method to my madness?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:00
Joined
Feb 28, 2001
Messages
26,999
I have no specific answer for you, but will tell you that the more you try to do in an event routine, the longer it will take to run. And remember that one event CANNOT interrupt another event. So the slowness MIGHT be caused simply by building a backlog of mouse-move events, which MUST be processed linearly.

Since I have never played that much with mouse-move, I can't tell you what to do, but perhaps my answer will explain what you see.

I never worried about mouse movement. What I did was worry about focus. If a user used a mouse click OR the TAB key, focus would change. So I did my color highlighing in the control's GotFocus event and did my control color normalization in the LostFocus event. Worked in my situation quite well.

You might want to consider that if your mouse's last position was greater than X away from the current position, it is moving fast and you don't want to do ANYTHING.

And one more note: I could never find a good "orange" either, but your FontWhite is simply the Access color constant vbWhite.
 

Users who are viewing this thread

Top Bottom