Microsoft KB Archive/231689

= BUG: Moving Controls on a Form Triggers Form_MouseMove Event =

Article ID: 231689

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q231689



SYMPTOMS
When you move controls on a form and the cursor is over the form, the form's MouseMove event gets triggered even if the cursor is not moving.



RESOLUTION
In this scenario, if you need to place code in the form's MouseMove event and want to be sure it runs only when the mouse is actually moving, you will need to set a flag before moving any control on the form. Check the flag in the MouseMove event before executing any code.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Start a new Standard EXE project. Form1 is created by default. Add a PictureBox control (Picture1) to Form1. Add a TextBox control (Text1) to Form1. Make it high enough to display multiple lines and set the Multiline property to True.  Place three CommandButtons on the form. Name them as below and set the captions accordingly: cmdMove      &Move cmdStart     &Start Log cmdStop      &End Log   Add the following code to the module of Form1: Option Explicit Dim iLog As Long

Private Sub cmdMove_Click Dim l As Integer, t As Integer l = Picture1.Left + Picture1.Width / 2 t = Picture1.Top Picture1.Move l, t End Sub

Private Sub cmdStart_Click Text1.Text = "" iLog = 1 End Sub

Private Sub cmdStop_Click iLog = 0 End Sub

Private Sub Form_Load iLog = 0 End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, _  x As Single, y As Single) If iLog = 1 Then Text1.Text = Text1.Text & "Form " & x & _ " " & y & " " & Date & vbCrLf End Sub  Save the project.</li> Press F5 to run the project.</li> Place the mouse over the form.</li> You can move Picture1 by using Alt+M.</li> You can start logging MouseMove events by using Alt+S.</li> Start logging and move Picture1. Every time you move the picture, a MouseMove event gets logged in the TextBox. Note that this only happens if the mouse is over the form.</li></ol>

Keywords: kbbug kbpending kbactivexevents KB231689

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.