dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.35k stars 965 forks source link

Cursor cannot load all supported file formats #3979

Open weltkante opened 3 years ago

weltkante commented 3 years ago

.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

WinForms is using IPicture interop 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. For streams this requires saving the stream to a file first, though.

grafik

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"));

JeremyKuhne commented 1 month ago

Not technically System.Drawing, but marking it as such as it is logically closer to Icon for this feature (so I'm more likely to notice it when looking at graphics resource related code).