Getting Icon from ResourceStream

心已入冬 提交于 2020-01-02 07:49:08

问题


I have a Icon.ico and in the Properties the Build Action is "Resource"...

I want to load that Icon in the Application..

I did something like this:

Icon theIcon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNameSpace.Icon.ico"));

that didnt worked (it says "Value of 'null' is not valid for 'stream'.")

What can I do?


回答1:


try using Application.GetResourceStream method

using(Stream stream = Application.GetResourceStream(new Uri("/MyNameSpace.ico")).Stream)
{
    Icon myIcon = new System.Drawing.Icon(stream);
}

more information from MSDN



来源:https://stackoverflow.com/questions/7873453/getting-icon-from-resourcestream

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