dotnet / dotnet/winforms

Cursor cannot load all supported file formats

Open
#3,979 1 comment 0 reactions 1 assignee Claimed by @JeremyKuhne View on GitHub
area-System.Drawing enhancement tenet-modernization
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

**.NET Core Version:**
all .NET Core and Desktop Framework

**Have you experienced this same bug with .NET Framework?:**
Yes

**Problem description:**

Loading a cursor making use of alpha transparency by filename or stream does not work correctly when done through WinForms and produces a black cursor image (possibly the cursor mask instead of the actual cursor?)

![grafik](https://user-images.githubusercontent.com/5845814/93937070-6fd4f280-fd27-11ea-8994-54a41823e603.png)

WinForms is [using `IPicture` interop](https://source.dot.net/#System.Windows.Forms/System/Windows/Forms/Cursor.cs,4a07b3923561f20f) to load cursors instead of the win32 cursor API and its unclear if OLE simply doesn't support alpha transparency, or if WinForms is doing something wrong in the interop.

**Expected behavior:**

The rendering should match the builtin hand cursor Windows uses (since in fact its the same file). You can also work around the bug by doing manual interop and calling [LoadCursorFromFile](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadcursorfromfilew). For streams this requires saving the stream to a file first, though.

![grafik](https://user-images.githubusercontent.com/5845814/93937047-62b80380-fd27-11ea-8ed9-3693fe220bdc.png)

**Minimal repro:**

Add a button and set the cursor to a file containing alpha transparency, for example the hand cursor distributed with Windows.

`button1.Cursor = new Cursor(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Cursors\\aero_link.cur"));`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.