Visual Basic > Visual Basic Forums > Visual Basic Power Packs > Why MouseMove event is different?
Ask a questionAsk a question
 

General DiscussionWhy MouseMove event is different?

  • Tuesday, October 27, 2009 1:43 PMSergiu Dudnic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hello, I wondering why the mouseMove event is different vs the normal controls?

    In the normal objects the MouseMoveEvent continues if the mouse was pressed(Down) and the cursor leaves the control.

    By ex, I have the following code:

    Public Class Form1
      Private mbox As New MoveBox
    
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        mbox.Location = New Point(30, 30)
        Me.Controls.Add(mbox)
      End Sub
    End Class
    
    Public Class MoveBox
      Inherits PictureBox
    
      Private _isActive As Boolean
      Public Sub New()
        Me.Size = New Size(10, 10)
        Me.BackColor = Color.Blue
      End Sub
    
      Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
        MyBase.OnMouseDown(e)
        _isActive = True
      End Sub
    
      Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
        MyBase.OnMouseUp(e)
        _isActive = False
      End Sub
    
      Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
        MyBase.OnMouseMove(e)
        If Me._isActive Then
          Me.Location = Me.Location + e.Location - New Point(Me.Width \ 2, Me.Height \ 2)
        End If
      End Sub
    End Class
    
    This code allows move a pictureBox with the pressed mouse.
    But when I try to inherit the OvalShape, The code does not work, cause the MouseMove event is not generated when the cursor leaves the shape control...
    Best regards, Sergiu

All Replies

  • Tuesday, October 27, 2009 2:03 PMCrazypennie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     



    You need to capture your mouse.

       Use  "MyControl.Capture=True"
  • Tuesday, October 27, 2009 2:22 PMSergiu Dudnic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You need to capture your mouse.
       Use  "MyControl.Capture=True"
    I see that ShapeContainer have a Capture property.

    But when set to True, the mouse moving tranformed the cursor icon in the "waiting" one... and the movement became very ugly...

    And in general this did not help... :)

    Best regards, Sergiu
  • Thursday, October 29, 2009 4:01 PMSergiu Dudnic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Bug reported to Microsoft...

    Best regards, Sergiu