> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/tutorials/code-tutorials/customizing-cursor-visuals/windows-desktop.md).

# Windows Desktop

### Introduction

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:

```csharp
FlatRedBallServices.Game.IsMouseVisible = true;

int originX = 0;
int originY = 0;

MouseCursor customCursor = MouseCursor.FromTexture2D(CursorTexture, originX, originY);
Mouse.SetCursor(customCursor);
```

For more information, see the following links:

* <https://docs.monogame.net/api/Microsoft.Xna.Framework.Input.Mouse.html#Microsoft_Xna_Framework_Input_Mouse_SetCursor_Microsoft_Xna_Framework_Input_MouseCursor_>
* <https://docs.monogame.net/api/Microsoft.Xna.Framework.Input.MouseCursor.html>

### Example Code - Changing the Cursor using Windows Forms and .cur File

{% hint style="info" %}
This approach only worked with the original XNA engine, and may work in the future if FRB adds support for MonoGame DirectX. This does not work with DesktopGL projects.
{% endhint %}

The following code loads a .cur file and sets the window's default cursor:

```csharp
var cursor = new System.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

{% hint style="info" %}
This approach only worked with the original XNA engine, and may work in the future if FRB adds support for MonoGame DirectX. This does not work with DesktopGL projects.
{% endhint %}

.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:

```csharp
// code obtained from StackOverflow, as posted by user "Nick"
// http://stackoverflow.com/questions/550918/change-cursor-hotspot-in-winforms-net
public struct IconInfo
{
    public bool fIcon;
    public int xHotspot;
    public int yHotspot;
    public IntPtr hbmMask;
    public IntPtr hbmColor;
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);
[DllImport("user32.dll")]
public static extern IntPtr CreateIconIndirect(ref IconInfo icon);

/// <summary>
/// Create a cursor from a bitmap without resizing and with the specified
/// hot spot
/// </summary>
static System.Windows.Forms.Cursor CreateCursor(System.Drawing.Bitmap bmp, int xHotSpot, int yHotSpot)
{
    IntPtr ptr = bmp.GetHicon();
    IconInfo tmp = new IconInfo();
    GetIconInfo(ptr, ref tmp);
    tmp.xHotspot = xHotSpot;
    tmp.yHotspot = yHotSpot;
    tmp.fIcon = false;
    ptr = CreateIconIndirect(ref tmp);
    return new System.Windows.Forms.Cursor(ptr);
}

void Initialize()
{
    var bitmap = 
        (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile("Content/GlobalContent/SmallCursor.png");
    var cursor = CreateCursor(bitmap, 0, 0);
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/flatredball/tutorials/code-tutorials/customizing-cursor-visuals/windows-desktop.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
