By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,675 Members | 1,721 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Using the MouseMove Property

missinglinq
Expert 2.5K+
P: 3,532
Having been asked, for the umpteenth time, how to use the MouseMove property to change the appearance of an object, I put together this short tutorial and sample database today. Perhaps it will be of use to some of you.

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
  1. Private Sub Form_Load()
  2.     Sets up the default appearance of the labels
  3.     lblMenuOptionA.ForeColor = vbBlack 'Sets the text color to black
  4.     lblMenuOptionA.SpecialEffect = 1   'Gives the label a raised, button-like appearance
  5.     lblMenuOptionA.BackStyle = 0       'Makes the label transparent. The color of the form behind the control is visible.
  6. End Sub
  7.  
Changes the background color of a label when the mouse rolls over the label
Expand|Select|Wrap|Line Numbers
  1. Private Sub lblMenuOptionA_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.     lblMenuOptionA.ForeColor = vbWhite 'Sets the text color to white
  3.     lblMenuOptionA.SpecialEffect = 1   'Gives the label a raised, button-like appearance
  4.     lblMenuOptionA.BackStyle = 1     'Makes the label's background color, as set in the Property Box, show
  5. End Sub
  6.  
Resets the default appearance of the label after the mouse moves off of the label
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.     lblMenuOptionA.ForeColor = vbBlack
  3.     lblMenuOptionA.SpecialEffect = 1
  4.     lblMenuOptionA.BackStyle = 0
  5. End Sub
Another application for MouseMove would be to show a label with a help message as a replacement for Access’ rather anemic ControlTips. The label is created and positioned in an appropriate place on the form. Unlike ControlTips, all of the usual label formatting functions can be utilized. In the label’s Property Box, the Visible property is set to NO so that the label doesn’t appear until called by the MouseMove event. When the mouse cursor moves over a form object, the label appears, then disappears when the mouse rolls off of the object. This is demonstrated in the MouseMoveHelpForm in the zipped database.

This pops up the Help message
Expand|Select|Wrap|Line Numbers
  1.  Private Sub ClientName_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.    lblClientNameHelp.Visible = True
  3. End Sub
  4.  
This causes the Help message to disappear when the mouse rolls off of the textbox
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.    lblClientNameHelp.Visible = False
  3. End Sub
  4.  
Please remember that the above only presents two examples of how MouseMove can be utilized. The actual number of uses is only limited by your users’ needs and youR own creativity!
Attached Files
File Type: zip MouseOverDemo.zip (27.9 KB, 4656 views)
May 18 '07 #1
Share this Article
Share on Google+