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.
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:
For more information, see the following links:
The following code loads a .cur file and sets the window's default cursor:
.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:
Windows RT supports a custom cursor. This article discusses how to modify the cursor to use custom visuals.
This project assumes a working Windows RT project. It also assumes that the cursor is visible. For more information on making the cursor visible, see this page.
Unfortunately to create a resource to hold the Cursor graphic you must create a C++ project. Don't worry, we won't do any C++ programming, but Visual Studio requires this project to create the proper resource files. To do this:
Open your project in Visual Studio
Right-click on the solution
Select Add->"New Project"
On the left select the category "Visual C++"->"Store Apps"->"Windows Apps"
Select the "DLL (Windows)" project type
Enter the name "ProjectForCursor"
Click OK
Next we'll add a resource file to contain our cursor resource. To do this:
Right-click on the newly-created project (ProjectForCursor)
Select Add->"Resource..."
Select "Cursor" when the popup appears and click "New"
Visual Studio creates a .cur file which contains the visuals for a cursor. This can be edited in many image editors. Users of Paint.NET can install a plugin to edit .cur files here.
First we need to build the C++ project to create the compiled resource file. To do this:
Right-click on the ProjectForCursor project
Select "Build"
Navigate to the build folder, which should be
Look for a .res file (mine was ProjectForCursor1.res)
We will now add this file to our game project. To do this:
Right click on the game project and select Add->"Existing Item..."
Navigate to the .res file mentioned above and select it. Notice that the file will be copied unless you explicitly select to link it.
Select File->"Save All" to save the addition of the resource file to the project
We must now modify the Visual Studio (C#) project by-hand. To do this:
Navigate to your game project's .csproj file
Open it in a text editor
Find the first PropertyGroup tab, which might appear as follows:
And add the Win32Resource tag inside of the PropertyGroup as follows:
Once finished save the file in the text editor.
Finally we can set the cursor in code. Unfortunately this must be done after the Game's Initialize method is called. We can do this in Update, but we only need to do it once so we will create a bool to keep track of whether the cursor has been set. First, add this bool outside of any function in Game1.cs:
Next, modify Game1.Update so it has the following code: