To load a custom mouse cursor in C# and VB.NET you can use the follwing snippet.

Sample C#

using System.Runtime.InteropServices;

[DllImport("user32.dll", EntryPoint = "LoadCursorFromFileW", CharSet = CharSet.Unicode)]
public static extern IntPtr LoadCursorFromFile(String str);

public void main()
{
	IntPtr cursorHandle = LoadCursorFromFile(file);
	this.Cursor = new Cursor(cursorHandle);
}

Sample VB.NET

Imports System.Runtime.InteropServices

Public Declare Function LoadCursorFromFile Lib "user32.dll" Alias "LoadCursorFromFileW" (ByVal str As String) As IntPtr

Public Sub main()
	Dim cursorHandle As IntPtr = LoadCursorFromFile(file)
	Me.Cursor = New Cursor(cursorHandle)
End Sub

One thought on “How to load a custom mouse cursor in C# and VB.NET”

Leave a Reply