-
Notifications
You must be signed in to change notification settings - Fork 954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Add ability to get modern Windows icons to System.Drawing.SystemIcons. #8802
Comments
Tagging subscribers to this area: @dotnet/area-system-drawing Issue DetailsBackground and motivationThe existing Providing a new method in API Proposalnamespace System.Drawing;
public static class SystemIcons
{
/// <summary>
/// Gets the specified stock shell icon.
/// </summary>
public static Icon GetStockIcon(StockIcon stockIcon);
}
// Matching https://learn.microsoft.com/windows/win32/api/shellapi/ne-shellapi-shstockiconid with
// Pascal casing and no abbreviations ("Assoc" to "Associations"), will still keep acronyms (CD, not CompactDisc).
public enum StockIcon
{
DocumentNoAssociation = 0,
DocumentWithAssociation = 1,
Application = 2,
Folder = 3,
OpenFolder = 4,
Drive525 = 5,
Drive35 = 6,
DriveRemovable = 7,
DriveFixed = 8,
DriveNetwork = 9,
DriveNetworkDisabled = 10,
DriveCD = 11,
DriveRAM = 12,
World = 13,
Server = 15,
Printer = 16,
// ...
} API Usageusing Icon icon = SystemIcons.GetStockIcon(StockIcon.Shield); Alternative DesignsWe could update the existing methods to use the current icons but:
We could also put the static method in RisksNo response
|
Overall it looks good. If there's a new icon, which isn't defined in StockIcon enum, one would still be able to use it. 👍
Are we planning to continue to add new values to StockIcon enum? Would it be a breaking change? |
As required, sure. I would not plan to block any requested value either. |
@JeremyKuhne Quoting from the previous thread:
Feel free to get inspiration from here. Results on different OS versions are illustrated here (see
Is it already decided? Today System.Drawing can be used independently from WinForms and I think this should remain this way. And the platform-independent System.Drawing primitives such as Anyway, until this feature gets into .NET my library is available here. May be useful also when targeting older frameworks or non-Windows platforms (though on non-Windows platforms it defaults to use some default icons). |
System.Drawing.Common will remain a separate package, it will just build from the Windows Forms repository and we (WinForms) will manage it. System.Drawing.Primitives (exchange types such as |
We added a Assuming that the shorter overload is passing Consider renaming namespace System.Drawing;
public static class SystemIcons
{
/// <summary>
/// Gets the specified stock shell icon.
/// </summary>
public static Icon GetStockIcon(StockIcon stockIcon);
public static Icon GetStockIcon(StockIcon stockIcon, StockIconOptions options);
}
[Flags]
public enum StockIconOptions
{
None = 0,
SmallIcon = 0x000000001,
ShellIconSize = 0x000000004,
LinkOverlay = 0x000008000,
Selected = 0x000010000,
}
// Matching https://learn.microsoft.com/windows/win32/api/shellapi/ne-shellapi-shstockiconid with
// Pascal casing and no abbreviations ("Assoc" to "Associations"), will still keep acronyms (CD, not CompactDisc).
public enum StockIcon
{
DocumentNoAssociation = 0,
DocumentWithAssociation = 1,
Application = 2,
Folder = 3,
OpenFolder = 4,
Drive525 = 5,
Drive35 = 6,
DriveRemovable = 7,
DriveFixed = 8,
DriveNetwork = 9,
DriveNetworkDisabled = 10,
DriveCD = 11,
DriveRAM = 12,
World = 13,
Server = 15,
Printer = 16,
// ...
} |
When documenting this, please make it clear whether the caller should eventually Dispose(). The SystemIcons.Application etc. properties cache the results and return Icon instances that ignore Dispose(). If GetStockIcon works differently, that will cause confusion. |
Discussed further with the API review board, I'll collapse to a single API with a default parameter and rename |
@KalleOlaviNiemitalo I will. Given the large number of icon types and options caching them doesn't seem plausible, so disposing them will be clearly called out. |
I've got the basic implementation in place, need to polish it up. |
Verified this on .NET 8.0 latest build: 8.0.100-preview.4.23179.4, saved the generated Icons using Icon.Save(), it behaves as expected. |
Background and motivation
The existing
SystemIcons
come from an older API that has icons that don't get updated with the OS. The new APISHGetStockIconInfo
is the way to get the current version of icons used in dialogs, etc.Providing a new method in
SystemIcons
would allow getting updated versions of icons and allow access to a number of additional icons. It additionally allows getting small icon versions, highlighted versions, link versions, etc.API Proposal
API Usage
Alternative Designs
We could update the existing methods to use the current icons but:
We could also put the static method in
StockIcons
, but that would make discoverability more difficult. Could potentially add to 'Icon'?Risks
No response
The text was updated successfully, but these errors were encountered: