VB6和VB.NET中對游標的編程

來源:互聯網
上載者:User
編程

在VB6中利用API對游標進行編程:

Option ExplicitPrivate Type POINTAPI    X As Long    Y As LongEnd TypePrivate Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPrivate Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As LongPublic Function GetXCursorPos() As Long   Dim pt As POINTAPI   GetCursorPos pt   GetXCursorPos = pt.XEnd FunctionPublic Function GetYCursorPos() As Long   Dim pt As POINTAPI   GetCursorPos pt   GetYCursorPos = pt.YEnd 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 =  " & GetYCursorPosEnd Sub'隱藏游標Private Sub Command1_Click()    ShowCursor FalseEnd Sub'顯示光線標Private Sub Command2_Click()    ShowCursor TrueEnd 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的文檔。

 



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。