The MouseMove Event is used to trigger an action when the user moves the mouse cursor over an object such as a textbox, label or command button. This can be applied to a number of routines. The attached zip file, MouseOverDemo, shows both of the routines outlined below in action.
The following code is used to set up a Menu Form for opening other forms or reports, using the the Click Event of labels. The label default appearance has the background color the same as the form, with the background color changing when the mouse rolls over a label. The MouseMoveMenuForm in the zipped database shows this code in action, presenting a Menu Form with four options.
Sets up the default appearance of the labels before the mouse is ever moved
Expand|Select|Wrap|Line Numbers
- Private Sub Form_Load()
- Sets up the default appearance of the labels
- lblMenuOptionA.ForeColor = vbBlack 'Sets the text color to black
- lblMenuOptionA.SpecialEffect = 1 'Gives the label a raised, button-like appearance
- lblMenuOptionA.BackStyle = 0 'Makes the label transparent. The color of the form behind the control is visible.
- End Sub
Expand|Select|Wrap|Line Numbers
- Private Sub lblMenuOptionA_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- lblMenuOptionA.ForeColor = vbWhite 'Sets the text color to white
- lblMenuOptionA.SpecialEffect = 1 'Gives the label a raised, button-like appearance
- lblMenuOptionA.BackStyle = 1 'Makes the label's background color, as set in the Property Box, show
- End Sub
Expand|Select|Wrap|Line Numbers
- Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- lblMenuOptionA.ForeColor = vbBlack
- lblMenuOptionA.SpecialEffect = 1
- lblMenuOptionA.BackStyle = 0
- End Sub
This pops up the Help message
Expand|Select|Wrap|Line Numbers
- Private Sub ClientName_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- lblClientNameHelp.Visible = True
- End Sub
Expand|Select|Wrap|Line Numbers
- Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- lblClientNameHelp.Visible = False
- End Sub