Programming for cursor in VB6 and VB.NET

xiaoxiao2021-03-06  57

Use the API to program the cursor in VB6:

Option expedition

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

'Get the location of the cursor on the screen

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

'Hidden cursor

Private submmand1_click ()

Showcursor False

End Sub

'Show cursor

Private sub fascist2_click ()

Showcursor True

End Sub

Using the Cursor class in VB.NET, it is easy to program the cursor: (You can get the position of the cursor, set the shape, display and hide the cursor)

'Hidden cursor

Private sub button1_click (byvale as system.object, byval e as system.eventargs) Handles Button1.click

Cursor.hide ()

End Sub

'Get the location of the cursor on the screen

Private Sub Form2_Mousemove (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

'Show cursor

Private sub Button2_click (byvalgend, byval e as system.eventargs) Handles Button2.click

Cursor.show ()

End Sub

Simple, more examples, you can refer to the API manual and the Framework documentation.

转载请注明原文地址:https://www.9cbs.com/read-113520.html

New Post(0)