dotnet / dotnet/winforms

Add `GetIPictureFromIcon()` to `AxHost`

Open
#13,999 0 comments 0 reactions 0 assignees View on GitHub
api-suggestion area-System.Drawing untriaged
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

### 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

```csharp
namespace System.Windows.Forms;

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

### API Usage

```csharp
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

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.