如何在运行时读取/显示图片框中的当前鼠标指针坐标?

时间:2013-07-18 06:39:15

标签: vb6

当运行时,我需要添加许多图像在我的图片框上,我有很多图像,并希望通过picture1.line连接它。 但我需要知道起点到终点的实际坐标(在运行时间内)。

关于如何读取/显示鼠标指针坐标的任何示例或任何想法?

1 个答案:

答案 0 :(得分:1)

在VB6中你可以这样做。创建一个新表单并添加以下代码:

Option Explicit

Private Type POINTAPI 'Type to hold coordinates
    X As Long
    Y As Long
End Type

'Function that gets current position
Private Declare Sub GetCursorPos Lib "User32" (lpPoint As POINTAPI)

'On mouse move, update form
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim rect As POINTAPI

    'Get position
    GetCursorPos rect

    'Print coordinates
    Me.Cls
    Print "Current X = " & rect.X
    Print "Current Y = " & rect.Y
End Sub