带有MouseMove和Click / MouseClick处理程序的VB.NET按钮

时间:2017-03-14 14:25:19

标签: vb.net winforms button click mousemove

我正在尝试将MouseMoveClick(或MouseClick)添加到按钮中。最终用户需要能够单击按钮添加元素,还能够将按钮拖动到特定位置以添加元素。我有两个功能独立工作。但是,当我添加两个处理程序时,MouseMove优先,并且不允许Click发生(尝试点击显示DragDropEffects.None效果)。

按钮:

Dim Button As New Button()
'Button Attributes

AddHandler Button.Click, AddressOf Button_Click
AddHandler Button.MouseMove, AddressOf Button_MouseMove

处理程序:

Private Sub Button_MouseMove(sender As Object, e As MouseEventArgs)
    Button.DoDragDrop("Button", DragDropEffects.Move)
End Sub

Private Sub Button_Click(sender As Object, e As EventArgs)
    'Add Element Function
End Sub

我也尝试使用MouseClick处理程序,结果相同:

AddHandler Button.MouseClick, AddressOf Button_MouseClick

Private Sub Button_MouseClick(sender As Object, e As MouseEventArgs)
    'Add Element Function
End Sub

1。)Click / MouseClick在实施MouseMove时无法触发的原因是什么?

2.。)使两种功能都可用的正确解决方法是什么?我是否需要执行MouseDownMouseUp处理程序,并跟踪鼠标移动的距离以确定我是否单击或拖动?

0 个答案:

没有答案