【发布时间】:2021-04-25 09:01:56
【问题描述】:
所以我在 Visual Basic 6.0 中开发了这个游戏,这是一个迷宫游戏,我希望我的鼠标光标设置在带有迷宫的表单的开始标签上,并且一旦表单被激活并获得焦点!
Dim label1 As New label=Start
【问题讨论】:
-
您能说得更具体些吗?你说的是什么形式?
所以我在 Visual Basic 6.0 中开发了这个游戏,这是一个迷宫游戏,我希望我的鼠标光标设置在带有迷宫的表单的开始标签上,并且一旦表单被激活并获得焦点!
Dim label1 As New label=Start
【问题讨论】:
我过去曾使用 Windows API 完成过类似的任务。在下面的示例中,表单包含一个名为“Label1”的标签,该标签位于表单的某个位置。当 Form 被激活时,光标会以 'Label1' 为中心:
Option Explicit
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Activate()
Dim wr As RECT
Dim tb As Long
Dim le As Long
Dim x As Long
Dim y As Long
'calculate coordinates
Call GetWindowRect(Me.hwnd, wr) 'window coordinates
tb = (Me.Height - Me.ScaleHeight) - (Me.Width - Me.ScaleWidth) / 2 'title bar height
le = (Me.Width - Me.ScaleWidth) * 0.5 'left edge of client area
'calculate center of label
x = wr.Left + ScaleX(le + Label1.Left + Label1.Width * 0.5, Me.ScaleMode, vbPixels)
y = wr.Top + ScaleY(tb + Label1.Top + Label1.Height * 0.5, Me.ScaleMode, vbPixels)
SetCursorPos x, y
End Sub
【讨论】: