How to get a Window's Icon in C#

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-04 08:48:30

问题


How can I get a Window's icon from its Pointer or Process/Process Name? The Icon shown in the corner of the Window or on the Task-bar or in the ALT-Tab menu.


回答1:


read about Icon.ExtractAssociatedIcon:

Returns an icon representation of an image that is contained in the specified file.

private void ExtractAssociatedIconEx()
{
    Icon ico =
        Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
    this.Icon = ico;

}

http://msdn.microsoft.com/en-us/library/system.drawing.icon.extractassociatedicon.aspx

This won't work on every process but it's a good start..

also take a look at those answers - How can I get the icon from the executable file only having an instance of it's Process in C#




回答2:


Would Icon.ExtractAssociatedIcon work for you?



来源:https://stackoverflow.com/questions/9968648/how-to-get-a-windows-icon-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!