winforms icon indicating copy to clipboard operation
winforms copied to clipboard

Add `GetIPictureFromIcon()` to `AxHost`

Open AchimStuy opened this issue 2 months ago • 0 comments

Background and motivation

I need an IPicture or IPictureDisp with type PICTYPE_ICON. Currently I can wrap my Icon into a Cursor and call GetIPictureFromCursor(), which extracts the icon from the cursor. So why not add an API directly?

https://github.com/dotnet/winforms/blob/0c37641a6f8d5462da4f1f26b3321e7d6432e4fc/src/System.Windows.Forms/System/Windows/Forms/ActiveX/AxHost.cs#L3537-L3538

API Proposal

namespace System.Windows.Forms;

public class AxHost
{
    protected static object GetIPictureFromIcon(Icon? icon)
        => icon is null ? null : icon.CreateIPictureRCW(copy: true);
}

API Usage

public class PictureConverter : AxHost
{
    public static IPicture ToIPicture(Icon icon)
    {
        return GetIPictureFromIcon(icon)
    }
}

Alternative Designs

No response

Risks

No response

Will this feature affect UI controls?

No

AchimStuy avatar Oct 29 '25 06:10 AchimStuy