在VB6中利用API对光标进行编程:
Option Explicit Private Type POINTAPI X As Long Y As Long End Type Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long Public Function GetXCursorPos() As Long Dim pt As POINTAPI GetCursorPos pt GetXCursorPos = pt.X End Function Public Function GetYCursorPos() As Long Dim pt As POINTAPI GetCursorPos pt GetYCursorPos = pt.Y End Function '得到光标在屏幕中的位置 Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Label1.Caption = "X Screen Position = " & GetXCursorPos Label2.Caption = "Y Screen Position = " & GetYCursorPos End Sub '隐藏光标 Private Sub Command1_Click() ShowCursor False End Sub '显示光标 Private Sub Command2_Click() ShowCursor True End Sub
在VB.NET中利用Cursor 类很简单地对光标进行编程:(可以获取和设置光标的位置,设置光标的形状,显示和隐藏光标)
'隐藏光标 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Cursor.Hide() End Sub '得到光标在屏幕中的位置 Private Sub Form2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove Me.Label1.Text = "X Screen Position = " & Cursor.Position.X Me.Label2.Text = "Y Screen Position = " & Cursor.Position.Y End Sub '显示光标 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Cursor.Show() End Sub
很简单的东西,更多的实例,可以参考API手册和Framework的文档。