如何在VB 2010中发送鼠标左键HOLD + DRAG?

时间:2012-03-04 18:49:14

标签: .net vb.net winforms winapi

我想在Visual Basic 2010中的应用程序中创建一个函数:

  • 模拟鼠标左键单击+保持并使用计时器勾选事件拖动
  • 为鼠标设置新的XY坐标以将项目拖动到新位置
  • 删除鼠标左键单击+保持命令

我该如何使用此功能?

1 个答案:

答案 0 :(得分:0)

我认为这就是你要找的东西

If Windows.Forms.Cursor.Position = Button2.PointToScreen(New Point(Button2.Width / 2, Button2.Height / 2)) Then
        Timer1.Enabled = False
        Button2_MouseDown(New Button, New MouseEventArgs(MouseButtons.Left, 1, Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y, 0))
    End If


    If Windows.Forms.Cursor.Position.X <> Button2.PointToScreen(New Point(Button2.Width / 2, Button2.Height / 2)).X Then

        If Windows.Forms.Cursor.Position.X > Button2.PointToScreen(New Point(Button2.Width / 2, Button2.Height / 2)).X Then

            Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X - 1, Windows.Forms.Cursor.Position.Y)

        ElseIf Windows.Forms.Cursor.Position.X < Button2.PointToScreen(New Point(Button2.Width / 2, Button2.Height / 2)).X Then


            Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X + 1, Windows.Forms.Cursor.Position.Y)


        End If

    End If

    If Windows.Forms.Cursor.Position.Y <> Button2.PointToScreen(New Point(Button2.Width / 2, Button2.Height / 2)).Y Then

        If Windows.Forms.Cursor.Position.Y > Button2.PointToScreen(New Point(Button2.Width / 2, Button2.Height / 2)).Y Then

            Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y - 1)

        ElseIf Windows.Forms.Cursor.Position.Y < Button2.PointToScreen(New Point(Button2.Width / 2, Button2.Height / 2)).Y Then


            Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y + 1)


        End If

    End If

这里发帖有点长,所以我创建了一个简单的项目。

示例程序Here

完整来源Here