在VB6中标签中的快速MouseMove

时间:2015-08-19 11:21:46

标签: vb6

lblRoom是标签的控制数组,brdrRoom是形状的控制数组,双击每个标签,我们可以用鼠标拖动它。当一个标签缓慢移动到其他标签上时没有问题,它移动平稳,但是当鼠标快速移动并且当到达其他标签的中心时,它会移动并且所选标签变为静止。 MouseMove的代码段名为:

Private Sub lblRoom_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    SelectedItemIndex = Index
    XPos = lblRoom(SelectedItemIndex).Left + X
    YPos = lblRoom(SelectedItemIndex).Top + Y
    If DragItem = True Then
       lblRoom(SelectedItemIndex).Left = XPos - lblRoom(SelectedItemIndex).Width / 2
       lblRoom(SelectedItemIndex).Top = YPos - lblRoom(SelectedItemIndex).Height / 2
       brdrRoom(SelectedItemIndex).Left = XPos - brdrRoom(SelectedItemIndex).Width / 2
       brdrRoom(SelectedItemIndex).Top = YPos - brdrRoom(SelectedItemIndex).Height / 2
    End If
End Sub

有什么问题?帮帮我:)

1 个答案:

答案 0 :(得分:2)

当您移动到另一个标签上方时,它也会收到MouseMove()个事件,因此您的程序可能会在您的两个标签之间切换SelectedItemIndex

要解决此问题,除了要拖动的标签之外,您应该忽略来自其他标签的鼠标事件。例如:

Private m_intDragIndex As Long

Private Sub lblRoom_DblClick(Index As Integer)
    m_intDragIndex = Index
End Sub

Private Sub lblRoom_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

    ' Only process events from the label that was double-clicked...
    If Index <> m_intDragIndex Then Exit Sub

    ...

End Sub

你还没有说过什么时候拖动应该停止,但无论你做什么来结束拖动,请务必设置m_intDragIndex = -1或其他一些“无效”值。< / p>