Windows Desktop games can display custom cursors. The default XNA window is a Windows Forms window, so customization of the cursor visuals is done the same as for any other Windows Forms app.
Example Code - Changing the Cursor using MonoGame
MonoGame 3.6 and newer introduces a method for changing the Windows cursor. The cursor can be set from a Texture2D. Assuming CursorTexture is a valid Texture2D:
Example Code - Changing the Cursor using Windows Forms and .cur File
The following code loads a .cur file and sets the window's default cursor:
var cursor =newSystem.Windows.Forms.Cursor("Content/GlobalContent/Cursor.cur");System.Windows.Forms.Form asForm = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(this.Window.Handle);asForm.Cursor= cursor;
Example Code - Changing the Cursor using Windows Forms and .png File
.cur files have a 32x32 pixel size limit. This can be bypassed by loading a .png into a Bitmap object, then using that object to construct a Cursor, as shown in the following code:
// code obtained from StackOverflow, as posted by user "Nick"// http://stackoverflow.com/questions/550918/change-cursor-hotspot-in-winforms-netpublicstructIconInfo{publicbool fIcon;publicint xHotspot;publicint yHotspot;publicIntPtr hbmMask;publicIntPtr hbmColor;}[DllImport("user32.dll")][return:MarshalAs(UnmanagedType.Bool)]publicstaticexternboolGetIconInfo(IntPtr hIcon,refIconInfo pIconInfo);[DllImport("user32.dll")]publicstaticexternIntPtrCreateIconIndirect(refIconInfo icon);/// <summary>/// Create a cursor from a bitmap without resizing and with the specified/// hot spot/// </summary>staticSystem.Windows.Forms.CursorCreateCursor(System.Drawing.Bitmap bmp,int xHotSpot,int yHotSpot){IntPtr ptr =bmp.GetHicon();IconInfo tmp =newIconInfo();GetIconInfo(ptr,ref tmp);tmp.xHotspot= xHotSpot;tmp.yHotspot= yHotSpot;tmp.fIcon=false; ptr =CreateIconIndirect(ref tmp);returnnewSystem.Windows.Forms.Cursor(ptr);}voidInitialize(){var bitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile("Content/GlobalContent/SmallCursor.png");var cursor =CreateCursor(bitmap,0,0);}