Visual Basic Development Bookmark and Share   
 Home > Visual Basic Power Packs > Why MouseMove event is different?
 

Why MouseMove event is different?

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
Sergiu Dudnic  Tuesday, October 27, 2009 1:43 PM



You need to capture your mouse.

Use "MyControl.Capture=True"
Crazypennie  Tuesday, October 27, 2009 2:03 PM
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
Sergiu Dudnic  Tuesday, October 27, 2009 2:22 PM
Bug reported to Microsoft...

Best regards, Sergiu
Sergiu Dudnic  Thursday, October 29, 2009 4:01 PM

You can use google to search for other answers

Custom Search

More Threads

• Location for Uploading Code Samples?
• No drawing controls in toolbox after install
• Setting 'NO' as the default in the msgbox
• Rectangle Shape delay
• handling drag & drop
• prob while getting ITTerminal object
• Changing the parent of a shape
• I am confused - plse help
• Question about Printing
• marker in a media file