|
Public Class Form1
''' <summary>
''' Provides ability to load color and/or animated cursor for the form or control.
''' Note: cursor must be embedded as native win32 resource in the assembly.
''' </summary>
Private Class ColorCursor
Private Declare Function LoadCursorAPI Lib "user32.dll" Alias "LoadCursorA" (ByVal hInstance As IntPtr, ByVal lpCursorName As String) As IntPtr
Public Shared Function LoadCursor(ByVal embeddedWin32ResourceID As Integer) As Cursor
Dim cursor As Cursor = TryLoadCursor(embeddedWin32ResourceID)
If cursor Is Nothing Then
Throw New System.ComponentModel.Win32Exception(Err.LastDllError)
Else
Return cursor
End If
End Function
Public Shared Function TryLoadCursor(ByVal embeddedWin32ResourceID As Integer) As Cursor
Dim hInstance As IntPtr = System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0))
Dim cPtr As IntPtr = LoadCursorAPI(hInstance, "#" & embeddedWin32ResourceID)
If cPtr = IntPtr.Zero Then
Return Nothing
Else
Return New Cursor(cPtr)
End If
End Function
End Class
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Cursor = ColorCursor.LoadCursor(104)
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.